django-views

ValueError: not enough values to unpack (expected 2, got 1)

↘锁芯ラ 提交于 2020-01-25 21:31:27
问题 the following is my code views.py from django.shortcuts import render from .forms import MedicineForm from .models import Medicine def index(request): all_medicine = Medicine.objects.order_by('id') return render(request, 'medicine/index.html', {'all_medicine': all_medicine}) def add(request): if request.method == 'POST': form = MedicineForm(request.POST) if form.is_valid(): new = Medicine() new.name = form.cleaned_data['药品名称'] new.price = form.cleaned_data['药品价格'] new.number = form.cleaned

DB / performance: layout of django model that rarely refers to its parent more than once

谁都会走 提交于 2020-01-25 12:55:08
问题 I have an app that's about presenting fictional simplified cities. Please consider the following Django models: class City(models.Model): name = models.CharField(...) ... TYPEGROUP_CHOICES = ( (1, 'basic'), (2, 'extra'), ) class BldgType(models.Model): name = models.CharField(...) group = models.IntegerField(choices=TYPEGROUP_CHOICES) class Building(models.Model): created_at = models.DateTimeField(...) city = models.ForeignKey(City) type = models.ForeignKey(BldgType) other_criterion = models

Django modal Submit form with foreign key not working

人盡茶涼 提交于 2020-01-25 08:14:05
问题 i have a model which is populated in a Bootstrap Modal, i am using class based view to render the form and submit it to the Database, however, when i click the save i get an error: AttributeError at /create_startupaboutform/ 'WSGIRequest' object has no attribute 'Startup' i am not sure if am assigning the FK correctly, however, for the Startup model it is working fine in function view but for class based view it is not. here is my code and i appreciate feedback on it. model.py: class Startup

How create a custom form in django with database values

余生长醉 提交于 2020-01-25 06:50:14
问题 model.py class Venue(models.Model): venue_Name = models.CharField(max_length=100) place = models.CharField(max_length=50) rent = models.IntegerField() parking_area = models.IntegerField() class Decoration(models.Model): rate = models.IntegerField() I have printed the values in database as radio buttons what i want to do is that i want to get the total sum i.e venue.rent + decoration.rate and print it in another page What shoud i give in form action I'm not that familiar with forms. html <form

How to include a form in multiple templates

跟風遠走 提交于 2020-01-25 00:39:40
问题 I have a Django app with two types of users, lets call them A and B. The two user types have different navigation bars. User type A has a link in their navigation bar to allow them to send a message. The send message form comes up in an overlay, so the form needs to be present in every template, or fetched over AJAX. These users can send a message from any/every page on the site, and each page has its own view. If a message has errors, users should be returned to the same page they were on,

DISTINCT ON fields is not supported by this database backend

无人久伴 提交于 2020-01-24 23:32:47
问题 I am using distinct to get the distinct latest values but it is giving me an error: DISTINCT ON fields is not supported by this database backend views.py class ReportView(LoginRequiredMixin, generic.TemplateView): template_name = 'admin/clock/report.html' def get_context_data(self, **kwargs): context = super(ReportView, self).get_context_data(**kwargs) context['reports'] = TimesheetEntry.objects.filter( timesheet_jobs__job_company = self.request.user.userprofile.user_company, ).distinct(

How perform patch operation on nested serializer with dictionary field

☆樱花仙子☆ 提交于 2020-01-24 12:18:49
问题 I have Model with dictionary object, in below example want to set and get daily availability example Currently I am able to read, want to make this to read and write, what should I do for this "teacher_date": [ { "day_available": "MON", "time_available": "Morning" }, { "day_available": "SAT", "time_available": "Afternoon" }, { "day_available": "SUN", "time_available": "Evening" } Here is my model.py class Availability(models.Model): uid = models.AutoField(verbose_name='ID', serialize=False,

How to make a login view for django custom user?

青春壹個敷衍的年華 提交于 2020-01-24 00:50:09
问题 I have made a custom user model using the AbstractUser , removed the username and replaced it with email and extended the model, tried creating superuser and it worked and also created some users by a signup form , logged in the admin interface and it worked however when tried to create a login form for the users it fails I tried this but it didn't work def LoginView(request): if request.method == 'POST': form = AuthenticationForm(data=request.POST) if form.is_valid(): user = form.get_user()

_reverse_with_prefix() argument after * must be an iterable, not int

╄→尐↘猪︶ㄣ 提交于 2020-01-23 07:58:35
问题 I have used Django's reverse multiple times in the past but getting this error today which doesn't seem intuitive enough to debug: TypeError: _reverse_with_prefix() argument after * must be an iterable, not int Here's the view where I am using it: from django.urls import reverse ... ... def show_scores_url(self, obj): scores_url = reverse('get_scores', args=(obj.pk)) return format_html('<a href="' + scores_url + '">Scores</a>') ... ... 回答1: As mentioned in this comment, putting a comma at the

_reverse_with_prefix() argument after * must be an iterable, not int

余生长醉 提交于 2020-01-23 07:58:26
问题 I have used Django's reverse multiple times in the past but getting this error today which doesn't seem intuitive enough to debug: TypeError: _reverse_with_prefix() argument after * must be an iterable, not int Here's the view where I am using it: from django.urls import reverse ... ... def show_scores_url(self, obj): scores_url = reverse('get_scores', args=(obj.pk)) return format_html('<a href="' + scores_url + '">Scores</a>') ... ... 回答1: As mentioned in this comment, putting a comma at the