django-models

global name 'get_user_model' is not defined

£可爱£侵袭症+ 提交于 2020-07-09 06:39:09
问题 NameError at /project/reset_password_confirm/MTQ-4c8-65d880f1c28996091226/ global name 'get_user_model' is not defined Request Method: POST Django Version: 1.9.1 Exception Type: NameError Exception Value: global name 'get_user_model' is not defined Exception Location: /root/django/studie/project/views.py in post, line 770 Python Executable: /usr/bin/python Python Version: 2.7.9 views.py from django.contrib.auth.models import User line 770: def post(self, request, uidb64=None, token=None, *arg

Nested django form for foreignkey model

Deadly 提交于 2020-07-09 05:27:21
问题 I have two models that look something like class Address(models.Model): line1 = models.CharField(max_length=128, help_text="Address Line 1") city = models.CharField(max_length=128) state = USStateField() zipcode = USZipCodeField() class Company(models.Model): name = models.CharField(max_length=100) address = models.ForeignKey('Address', on_delete=models.PROTECT) And I would like to generate a form that looks something like below, although I have no idea how to save the address from within a

Django: django-autocomplete-light does not work properly

回眸只為那壹抹淺笑 提交于 2020-07-08 10:51:32
问题 I'm using django-autocomplete-light in django 1.8. But I don't know how to use it in forms.py . Instead of autocomplete field I see a select field. I followed the instructions from here. In models.py I have: class icd_10(models.Model): id = models.IntegerField(unique=True,primary_key=True,null=False,blank=False) icd_10_desc = models.CharField('ICD-10 description',max_length=80,null=True,blank=True) icd_10_code = models.CharField('ICD-10 code',max_length=10,null=True,blank=True) def __str__

Django: django-autocomplete-light does not work properly

拈花ヽ惹草 提交于 2020-07-08 10:51:06
问题 I'm using django-autocomplete-light in django 1.8. But I don't know how to use it in forms.py . Instead of autocomplete field I see a select field. I followed the instructions from here. In models.py I have: class icd_10(models.Model): id = models.IntegerField(unique=True,primary_key=True,null=False,blank=False) icd_10_desc = models.CharField('ICD-10 description',max_length=80,null=True,blank=True) icd_10_code = models.CharField('ICD-10 code',max_length=10,null=True,blank=True) def __str__

Defining an Abstract model with a ForeignKey to another Abstract model

ぃ、小莉子 提交于 2020-07-07 07:43:20
问题 I'm trying to build two abstract classes called SurveyQuestionBase and SurveyResponseBase that will serve as templates to quickly define new concrete Models for implementing specific surveys on our website. The issue I am having is in enforcing that the SurveyResponseBase model, when made concrete, should define a ForeignKey to a concrete model of SurveyQuestionBase . Django does not allow us to define ForeignKeys to abstract classes so I cannot, for instance, do this: question = models

Defining an Abstract model with a ForeignKey to another Abstract model

淺唱寂寞╮ 提交于 2020-07-07 07:41:22
问题 I'm trying to build two abstract classes called SurveyQuestionBase and SurveyResponseBase that will serve as templates to quickly define new concrete Models for implementing specific surveys on our website. The issue I am having is in enforcing that the SurveyResponseBase model, when made concrete, should define a ForeignKey to a concrete model of SurveyQuestionBase . Django does not allow us to define ForeignKeys to abstract classes so I cannot, for instance, do this: question = models

Django .update doesn't call override save?

风格不统一 提交于 2020-07-07 05:20:28
问题 I am trying to call this overrride save method in models: def save(self, *args, **kwargs): if self.done is True: if self.averagepa is None: pass elif self.averagepa < 26: self.links = 5 elif self.averagepa < 31: self.links = 10 elif self.averagepa < 36: self.links = 15 elif self.averagepa < 41: self.links = 20 else: self.links = 99 super(KW, self).save(*args, **kwargs) This works perfectly if I just save model in admin panel. But when I try to update it via ./manage.py shell like this: KW

Django .update doesn't call override save?

假装没事ソ 提交于 2020-07-07 05:20:26
问题 I am trying to call this overrride save method in models: def save(self, *args, **kwargs): if self.done is True: if self.averagepa is None: pass elif self.averagepa < 26: self.links = 5 elif self.averagepa < 31: self.links = 10 elif self.averagepa < 36: self.links = 15 elif self.averagepa < 41: self.links = 20 else: self.links = 99 super(KW, self).save(*args, **kwargs) This works perfectly if I just save model in admin panel. But when I try to update it via ./manage.py shell like this: KW

Provide a default for ForeignKey field on existing entries in Django

落爺英雄遲暮 提交于 2020-07-04 13:18:08
问题 I have this model: class Movie(models.Model): # here are some fields for this model to which I added the following field (the database was already populated with Movie models): user = models.ForeignKey(User, default=1) I ran the commands 'makemigrations' and then 'migrate': python manage.py makemigrations myapp python manage.py migrate but it doesn't work. What I want to do is to add the 'user' field to Movie objects and provide a default for it for all the existing Movie objects in my

Django queryset attach or annotate related object field

余生长醉 提交于 2020-07-04 10:51:42
问题 It is needed to attach to queryset results related object field. Models: class User(models.Model): name = models.CharField(max_length=50) friends = models.ManyToManyField('self', through='Membership', blank=True, null=True, symmetrical=False) class Membership(models.Model): status = models.CharField(choices=SOME_CHOICES, max_length=50) from_user = models.ForeignKey(User, related_name="member_from") to_user = models.ForeignKey(User, related_name="member_to") I can do this: >>> User.objects.all