django-forms

Django forms for related objects

#models.py class Legs: left = TextField(default='-') right = TextField(default='-') class Animal: #possibly, more fields description = TextField() front_legs = OneToOneField(Legs, related_name='front_animal') back_legs = OneToOneField(Leg,s related_name='back_animal') #forms.py class LegsForm(ModelForm): """" Not needed...

How do I reference the underlying model of a django model form object?

When creating a form, I wish to use one field on the model as a label to go with another field that I'm updating. I've overridden the BaseModelFormSet with a new _init__ method, like this: class BaseMyFormSet(BaseModelFormSet): def __init__(self, *args, **kwargs): super(BaseMyFormSet, self).__init__(*args, **kwargs) for ...

Inserting values into a formset

I have a modelform which has a user_id field that I have excluded from the form. This form is made into a modelformset. The reason I have the user field excluded is because it's not an editable value. I don't want that value to go to the HTML form where it can be tampered with by naughty user. When I try to save this model formset, I ge...

Django upload form attempting to clean an undefined widget?

Getting a rendering error for this form: 'NoneType' object has no attribute 'widget' http://dpaste.com/88585/ Any ideas? view def your_photos_upload(request): if request.method == 'POST': form = MemorialUserPhotosForm(request.FILES) if form.is_valid(): form class MemorialUserPhotosForm(ModelForm): image = f...

Styling django non-field errors on forms

If I look in Django's forms.py, as_p() calls _html_output(), which styles field errors with self.error_class() (although I can't locate the definition of that). However, _html_output() does NOT style non_field_errors (a.k.a. top_errors in the code). How does one style the non-field errors? Cut and paste all of _html_output? I am usin...

Django admin, inlines populate field's

Hi guys, there is something that i would like do. i have 4 class: class delivery(models.Model): name= models.CharField(max_length=100) date_join= models.DateField() .... class Town(models.Model): delivery_guy = models.ForeignKey(delivery) name = models.CharField(max_length=100) .... class...

Django admin, section without "model" ?

H guys, Django admin, all section (menu links) come form models with database table, but, what happen if i need a section without model (no database table) that bring me data from other section with model? Any idea? Thanks ...

Django inlines, how i know which was edited?

Hi guys, i would like to know , how ill know which inlines forms was edited? In my case i want to save a custom value for every inlines form when was edited, so, how i know how much was edited or which one? thanks ...

[Django] Group Input in Forms

Hi! I've this django form class CustomerForm(forms.Form): first_name = forms.CharField(label=_('Nome'), max_length=30) last_name = forms.CharField(label=_('Cognome'), max_length=30) business_name = forms.CharField(label=_('Ragione Sociale'), max_length=100) ...

getting the user from a admin validation class

Hello, I am trying to control admin item entry where non-super user accounts can't save a ChannelStatus model input that has a date attribute which is older than 2 days. I need to get the user so that I can check if the request is a reqular or a super user but couldn't achieve this. I have already tried "request.user.is_superuser", "use...

Require one of a set of fields in a form to be valid.

How do I make a Django form where the user can choose between several ways of providing the data, and I need one of them to be valid. Say that I have a user profile where the user can choose between profile picture as URL or a imagefile: class UserProfile(forms.Form): picture_url = forms.URLField() picture_file = forms.ImageFie...

Store django forms.MultipleChoiceField in Models directly

Say I have choices defined as follows: choices = (('1','a'), ('2','b'), ('3','c')) And a form that renders and inputs these values in a MultipleChoiceField, class Form1(forms.Form): field = forms.MultipleChoiceField(choices=choices) What is the right way to store field in a model. I can of course loop thr...

Easiest way to remove leading zeroes from Django TimeInput form widgets?

I'm building an Django app that requires users to enter the time of day in TimeFields and I'm trying to format this as nicely as possible. My code currently looks like this: start = forms.TimeField(widget=forms.TimeInput(format="%I:%M %p")) end = forms.TimeField(widget=forms.TimeInput(format="%I:%M %p")) Where the values in the format...

Narrowing choices in Django form

I have a model like: CAMPAIGN_TYPES = ( ('email','Email'), ('display','Display'), ('search','Search'), ) class Campaign(models.Model): name = models.CharField(max_length=255) type = models.CharField(max_length=30,choices=CAMPAIGN_TYPES,default='display') ...

Auto-generate form fields for a Form in django

I have some models and I want to generate a multi-selection form from this data. So the form would contain an entry for each category and the choices would be the skills in that category. models.py class SkillCategory(models.Model): name = models.CharField(max_length=50) class Skill(models.Model): name = models.CharField(max_l...

dev server hiccups after saving from in Django admin

This is starting bug me: whenever I use the django admin to add or edit a record, I hit save and expect a confirmation page, but the result is a page that tells me the website is experiencing an error (it's not a Django page with a traceback, just a default view in my browser). If I hit reload or back in the browser, it takes me back to ...

Select item in Django admin inline with radio buttons

Here's part of my models.py: class Person(models.Model): birth_year = WideYear(null=True, blank=True) birth_year_uncertain = models.BooleanField() death_year = WideYear(null=True, blank=True) death_year_uncertain = models.BooleanField() flourit_year = WideYear(null=True, blank=True) flourit_year_uncertain = model...

handling forms in django (beginner question)

Hello, I am a primarily a PHP guy. How would I handle forms in django? I managed to create a form, model and a view. Now I want to save my data into the database. #forms.py from django import forms import datetime class CommentForm(forms.Form): name = forms.CharField(initial='Your name') comment = forms.CharField(initial='You ...

Django Admin Fieldsets

Hi Trying to undertstand Django Admin a bit better, but I find the django documentation a bit lacking sometimes (or perhaps my capacity to understand). I know you can use fieldsets to control the layout of certain admin pages. What I cant seem to grasp is what the fieldset names are. If i have the following class Clas Demo(model.Mode...

django init function with attrs in Form

Hi guys, im using Django Profiles, and i need to make some change in the profile form. In the normal way my form is fine completly, but now i would like a litter change, add jquery for repopulate a select form. The problem is that Django Profile make the form from the model, so i would like to add a attribute id to the select form (i d...