django-forms

Nested and Segmented Crispy Layouts

╄→尐↘猪︶ㄣ 提交于 2020-01-02 13:44:50
问题 TLDR Question: How do you make one crispy form with a ¿segmented?(not sure if this is considered inline) layout with multiple models(some related, some not). I am trying to understand several things in Django: forms, formsets, nested forms, and crispy, and I've been at it for a while, and feel I am close, just need someone to help connect the dots. I'm not sure how to accomplish it without crispy, so I started down this path thinking crispy was the solution. Please correct if I am wrong,

Django: Model clean method called before form clean

元气小坏坏 提交于 2020-01-02 13:19:32
问题 I don't understand, why is my model clean method called before full form validation. I have required fields in my form. If I don't fill them, I don't get form errors, instead of, the model clean method is called (so I suppose it's because save is called). It crashes in models clean() method: if self.date_from > self.date_to can't compare datetime.date to NoneType Because I didn't filled date_to field. I think that form should have handle it and raise ValidationError and models save() shouldn

Django: Model clean method called before form clean

无人久伴 提交于 2020-01-02 13:19:15
问题 I don't understand, why is my model clean method called before full form validation. I have required fields in my form. If I don't fill them, I don't get form errors, instead of, the model clean method is called (so I suppose it's because save is called). It crashes in models clean() method: if self.date_from > self.date_to can't compare datetime.date to NoneType Because I didn't filled date_to field. I think that form should have handle it and raise ValidationError and models save() shouldn

How to specify Select and RadioSelect in a ModelForm?

巧了我就是萌 提交于 2020-01-02 10:18:28
问题 I am converting a survey from a Form to a ModelForm in Django 1.6.2. Can anyone tell me what is the equal of forms.ChoiceField(widget=forms.Select(), and forms.ChoiceField(widget=forms.RadioSelect() using ModelForm ? I have tried widget=models.Select() or widget=models.RadioSelect() but it keeps giving the error AttributeError: 'module' object has no attribute 'Select' AttributeError: 'module' object has no attribute 'RadioSelect' Old Code forms.py class SurveyFormB(forms.Form): #Do you own a

Class Based Generic UpdateView inline

落花浮王杯 提交于 2020-01-02 09:02:39
问题 I have the following models class Cv(models.Model): name = models.CharField(_('name'), max_length=250) objective = models.CharField(_('objective'), max_length=250) slug = models.SlugField(editable=False) class Position(models.Model): cv = models.ForeignKey(Cv, verbose_name=_('cv')) start = models.DateField(_('start')) end = models.DateField(_('end')) name = models.CharField(_('name'), max_length=250) currently_employed = models.BooleanField(_('currently employed')) sector = models

Class Based Generic UpdateView inline

ⅰ亾dé卋堺 提交于 2020-01-02 09:02:14
问题 I have the following models class Cv(models.Model): name = models.CharField(_('name'), max_length=250) objective = models.CharField(_('objective'), max_length=250) slug = models.SlugField(editable=False) class Position(models.Model): cv = models.ForeignKey(Cv, verbose_name=_('cv')) start = models.DateField(_('start')) end = models.DateField(_('end')) name = models.CharField(_('name'), max_length=250) currently_employed = models.BooleanField(_('currently employed')) sector = models

Django Form with no required fields

对着背影说爱祢 提交于 2020-01-02 07:10:13
问题 I want to make a form used to filter searches without any field being required. For example given this code: models.py: class Message(models.Model): happened = models.DateTimeField() filename = models.CharField(max_length=512, blank=True, null=True) message = models.TextField(blank=True, null=True) dest = models.CharField(max_length=512, blank=True, null=True) fromhost = models.ForeignKey(Hosts, related_name='to hosts', blank=True, null=True) TYPE_CHOICES = ( (u'Info', u'Info'), (u'Error', u

Django ModelForm Validate custom Autocomplete for M2M, instead of ugly Multi-Select

痴心易碎 提交于 2020-01-02 07:04:29
问题 Given the following models (cut down for understanding): class Venue(models.Model): name = models.CharField(unique=True) class Band(models.Model): name = models.CharField(unique=True) class Event(models.Model): name = models.CharField(max_length=50, unique=True) bands = models.ManyToManyField(Band) venue = models.ForeignKey(Venue) start = models.DateField() end = models.DateField() The admin area works great for what I'm doing, but I'd like to open the site up a bit so that certain users can

Django - ForeignKey field initial value definition in Admin

◇◆丶佛笑我妖孽 提交于 2020-01-02 06:16:48
问题 I have a Person model, which has a ForeignKey field to itself, called mother . When the user goes to the 'add' admin form, I want to define an initial value for mother , in case there is a GET('mother') parameter, or leave it blank, in case there is not. I have actually 2 questions: How to access request inside ModelAdmin ? How to define initial value for a ForeignKey field? In models.py: class Person(models.Model): name=models.CharField() mother=models.ForeignKey('self') In admin.py: class

Django, UserChangeForm errors

安稳与你 提交于 2020-01-02 05:48:07
问题 I'm making a custom user form where a user can go in to change some details. It got two errors that I cannot understand what the problem is though. The first problem is that the form doesn't fill out the user details. And it seems to be because self is empty when form is initialized, why? And the second problem is that when I submit this form, it will complain about some KeyError, which I don't get either. I've pasted the code and stacktrace. Trackback Environment: Request Method: POST