django-models

django : using select_related and get_object_or_404 together

試著忘記壹切 提交于 2020-01-28 13:16:10
问题 Is there any way of using get_object_or_404 and select_related together or any other way to achieve the result of using these two together(except from putting it in try/except)?? 回答1: Yes. obj = get_object_or_404(MyModel.objects.select_related(), whatever=whatever) 来源: https://stackoverflow.com/questions/6624530/django-using-select-related-and-get-object-or-404-together

How to validate the registered users with login in django?

喜你入骨 提交于 2020-01-26 04:49:12
问题 Here I am using a non custom user model for saving the users registered and their details are stored in user_requirement model now I want to validate before logging in to the dashboard My models.py: class user(models.Model): username=models.CharField(max_length=20) email=models.CharField(max_length=50,unique=True) password=models.CharField(max_length=50,default='0000000') created_at = models.DateTimeField(default=datetime.now) updated_at = models.DateTimeField(default=datetime.now) def __str_

Using Django Models across Apps

丶灬走出姿态 提交于 2020-01-25 21:20:47
问题 Good afternoon, I have seen similar questions but none of the answers really resonate with me. I am new to django development and am trying to get use to the models. My question is how do I utilize a model from one app in another appropriately? For instance, I have a project, Project 1 that consists of the a Person app that manages the users profile. This app has the model for a person, but then that person is used in Activities for the activities they have completed, and another progress in

Using Django Models across Apps

↘锁芯ラ 提交于 2020-01-25 21:20:32
问题 Good afternoon, I have seen similar questions but none of the answers really resonate with me. I am new to django development and am trying to get use to the models. My question is how do I utilize a model from one app in another appropriately? For instance, I have a project, Project 1 that consists of the a Person app that manages the users profile. This app has the model for a person, but then that person is used in Activities for the activities they have completed, and another progress in

Django 1.7 remove field. Unknown field(s) (field) specified for Model

和自甴很熟 提交于 2020-01-25 17:35:11
问题 I have already many models in my application. I have already used migrations in my project. But when I want to remove a field from a model, the makemigration command show me : Unknown field(s) (field) specified for Model Where (fields) is equal to the field's name and Model is the model's name ? Do you have any solution to resolve this issue ? 回答1: You may try modifying auto_now and auto_now_add with default = 'xxx', then the field can be called 来源: https://stackoverflow.com/questions

Django 1.7 remove field. Unknown field(s) (field) specified for Model

折月煮酒 提交于 2020-01-25 17:35:08
问题 I have already many models in my application. I have already used migrations in my project. But when I want to remove a field from a model, the makemigration command show me : Unknown field(s) (field) specified for Model Where (fields) is equal to the field's name and Model is the model's name ? Do you have any solution to resolve this issue ? 回答1: You may try modifying auto_now and auto_now_add with default = 'xxx', then the field can be called 来源: https://stackoverflow.com/questions

django-seo setting up, models aren't loaded yet

匆匆过客 提交于 2020-01-25 10:59:46
问题 I'm trying to add django-seo into my site. But I can't cope with setting up. I followed instructions documentation, but error occurs. This is what I did: Installed django-seo packacge Added rollyourown.seo to INSTALED_APPS Created seo.py file in my site content app And this is what I wrote into seo.py file: from rollyourown import seo class Metadata(seo.Metadata): title = seo.Tag(head=True, max_length=68) description = seo.MetaTag(max_length=155) keywords = seo.KeywordTag() heading = seo.Tag

Django - Annotate with count across ManytoMany relationships

白昼怎懂夜的黑 提交于 2020-01-25 09:31:08
问题 I am not able to find the way to annotate a queryset with a count of how many times an element is used in a many-to-many relationship. class Profile(models.Model): [...] # Profile can have multiple roles roles = models.ManyToManyField('Role', blank=True) [...] class Role(models.Model): company = models.ForeignKey(Company, on_delete=models.CASCADE) name = models.CharField(blank=True, max_length=30) description = models.CharField(blank=True, max_length=300) [...] For example I would have 5

Django - empty form cannot be saved in database

浪尽此生 提交于 2020-01-25 07:49:05
问题 I have a form in which, user specifies lawyer-spec and save the data to the database. However I get an error that **null value in column "lawyer_spec" violates not-null constraint** So the data from the form is not processed properly. EDIT: mthod form_invalid prints empty line, and then two numbers ('pk' and 'lawyer_id') forms.py class MakeAppointmentForm(forms.ModelForm): first_name = forms.CharField(required=True) class Meta: model = CalendarAppointmentsReserved fields = ['case'] def __init

Django: Model UniqueConstraint gives an error when migrating

我与影子孤独终老i 提交于 2020-01-25 06:57:47
问题 In my Django project the in one of the model I need to use two UniqueConstraint instances. But when I add that and do the migration after running makemigrations it gives an error in the terminal. Model class: class MyDays(models.Model): class Meta: verbose_name = "My Day" verbose_name_plural = "My Days" constraints = [ models.UniqueConstraint(fields=['userid', 'date', 'from'], condition=Q(status=1), name='user_date_from_a'), models.UniqueConstraint(fields=['userid', 'date', 'to'], condition=Q