django-forms

Django reverse lookup of foreign keys

∥☆過路亽.° 提交于 2019-12-17 04:56:25
问题 I have a venue, this venue has many events happening there. My models look like this: class Event(models.Model): title = models.CharField(max_length=200) date_published = models.DateTimeField('published date',default=datetime.now, blank=True) date_start = models.DateTimeField('start date') date_end = models.DateTimeField('end date') def __unicode__(self): return self.title description = models.TextField() price = models.IntegerField(null=True, blank=True) venue = models.ForeignKey(Venue)

Django reverse lookup of foreign keys

こ雲淡風輕ζ 提交于 2019-12-17 04:56:22
问题 I have a venue, this venue has many events happening there. My models look like this: class Event(models.Model): title = models.CharField(max_length=200) date_published = models.DateTimeField('published date',default=datetime.now, blank=True) date_start = models.DateTimeField('start date') date_end = models.DateTimeField('end date') def __unicode__(self): return self.title description = models.TextField() price = models.IntegerField(null=True, blank=True) venue = models.ForeignKey(Venue)

How can I restrict Django's GenericForeignKey to a list of models?

扶醉桌前 提交于 2019-12-17 03:24:15
问题 Is there a way of telling django that a model having a contenttypes GenericForeignKey can only point to models from a predefined list? For example, I have 4 models: A, B, C, D and a model X that holds a GenericForeignKey. Can I tell X that only A & B are allowed for the GenericForeignKey? 回答1: For example, your apps are app and app2 and there are A, B models in app and there are C, D models in app2. you want to see only app.A and app.B and app2.C from django.db import models class TaggedItem

How can I build multiple submit buttons django form?

馋奶兔 提交于 2019-12-17 02:39:09
问题 I have form with one input for email and two submit buttons to subscribe and unsubscribe from newsletter: <form action="" method="post"> {{ form_newsletter }} <input type="submit" name="newsletter_sub" value="Subscribe" /> <input type="submit" name="newsletter_unsub" value="Unsubscribe" /> </form> I have also class form: class NewsletterForm(forms.ModelForm): class Meta: model = Newsletter fields = ('email',) I must write my own clean_email method and I need to know by which button was form

Django: multiple models in one template using forms [closed]

谁说胖子不能爱 提交于 2019-12-17 01:33:15
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year . I'm building a support ticket tracking app and have a few models I'd like to create from one page. Tickets belong to a Customer via a ForeignKey. Notes belong to Tickets via a ForeignKey as well. I'd like to have the option of selecting a Customer (that's a whole separate project)

Django - Uploaded file type validation

旧巷老猫 提交于 2019-12-14 04:25:11
问题 I need to validate the file type of the uploaded file and should allow only pdf, plain test and MS word files. Here is my model and and the form with validation function. But, I'm able to upload files even without the extension. class Section(models.Model): content = models.FileField(upload_to="documents") class SectionForm(forms.ModelForm): class Meta: model = Section FILE_EXT_WHITELIST = ['pdf','text','msword'] def clean_content(self): content = self.cleaned_data['content'] if content: file

Django UserCreationForm for custom model is outputting 3 password fields password, password1, and password2

↘锁芯ラ 提交于 2019-12-14 04:22:05
问题 Ok, so I have a user registration form based on AbstractUser that replaces the Django model in my settings.py, the model only adds a couple of fields I needed for info on the users, when I tested the registration form the user did not get created, I debugged and found that both last login and date joined where required so I set them as hidden inputs with value of {% now "SHORT_DATE_FORMAT" %} that solved the first two errors however there is a third error that says the field password is

How to change the layout for templates in a Django Form-Wizard?

╄→尐↘猪︶ㄣ 提交于 2019-12-14 04:04:15
问题 I am using Django's Form Wizard package to create a 4-step form. I have created forms for each of the four steps. It's working fine. In my case I have created 4 separate templates and each step of the form wizard uses its own template. But each of these templates that I have created is substantially the same. Below is the code that is in each one. I cut and pasted this from elsewhere. It works, but I don't fully understand how or why: <form action="" method="post">{% csrf_token %} <table> {{

Django: How do I use a different form_class with django-registration

China☆狼群 提交于 2019-12-14 03:44:49
问题 I want django-registration (version 0.8) to use my custom form rather than the default one. However, I want to continue to use the default django-registration view. What should the rest of the line below look like to achieve this? (r'^accounts/register'...), I've tried this below but get a syntax error: (r'^accounts/register/$', 'registration.views.register', {'form_class': 'MyRegistrationForm'}, name='registration_register'), And when I try this one below I get register() takes at least 2

Add fields to Django ModelForm that aren't in the model

大兔子大兔子 提交于 2019-12-14 03:43:27
问题 I have a model that looks like: class MySchedule(models.Model): start_datetime=models.DateTimeField() name=models.CharField('Name',max_length=75) With it comes its ModelForm: class MyScheduleForm(forms.ModelForm): startdate=forms.DateField() starthour=forms.ChoiceField(choices=((6,"6am"),(7,"7am"),(8,"8am"),(9,"9am"),(10,"10am"),(11,"11am"), (12,"noon"),(13,"1pm"),(14,"2pm"),(15,"3pm"),(16,"4pm"),(17,"5pm"), (18,"6pm" startminute=forms.ChoiceField(choices=((0,":00"),(15,":15"),(30,":30"),(45,