django-forms

django form

is anybody know how to log the username who is currently loged in in form.py ...

What's the easiest way to perform total calculations on child objects?

I need to perform a range of simple calculations on an Invoice model object, which has a number of Order children associated with it that hold the order quantity and order value etc. This is all managed through the admin form for Invoice (with order as inlines) The code I'm working with now performs these calcs like this: Invoice (mod...

generating form for a simple survey-app

I am writing an app for a simple survey. For possible answers I need "Yes/Now", "1 out of 1 to 5", and a short text In the admin it should be selectable, what kind of answer should be given. My models: from django.db import models from django.contrib.contenttypes.models import ContentType CHOICES=((1,'excactly true'),(2,'mostly true...

Where does the widgets/foreign.html file reside in django trunk?

I would like to override (create custom) widgets/foreign.html template for a ForeignKey field but can't find this in the source. Browsing the Django SVN respository I can find these files at revision: 7966, but they are removed after this revision; http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/templates/widget?...

Returning pure Django form errors in JSON

Hi I have a Django form which I'm validating in a normal Django view. I'm trying to figure out how to extract the pure errors (without the HTML formatting). Below is the code I'm using at the moment. return json_response({ 'success' : False, 'errors' : form.errors }) With this, I get the infamous proxy object e...

Admin Form Integration for Custom Model Fields in Django

I need a model field composed of a numeric string for a Django app I'm working on and since one doesn't exist I need to roll my own. Now I understand how "get_db_prep_value" and such work, and how to extend the Model itself (the django documentation on custom model fields is an invaluable resource.), but for the life of me I can't seem ...

Models unique_together constraint + None = fail?

2 questions: How can I stop duplicates from being created when parent=None and name is the same? Can i call a model method from within the form? Please see full details below: models.py class MyTest(models.Model): parent = models.ForeignKey('self', null=True, blank=True, related_name='children') name = models.CharField(max...

saving inlineformset_factory data

@render_to('edit_operation.html') def edit_operation(request, pk): from forms import OpBaseForm, OperationForm from django.forms.models import inlineformset_factory op = Operation.objects.get(pk=pk) OpBaseFormSet = inlineformset_factory(Operation, OpBase, form=OpBaseForm, extra=5, ) if request.method == "POST": form = Oper...

dynamically populating fields in a formset

I have two models that looks like this: class RouteBase(models.Model): base = models.ForeignKey("Base") route = models.ForeignKey("Route") sequence = models.IntegerField() class Route(models.Model): bases = models.ManyToManyField("Base", through="RouteBase", blank=True) description = models.TextField(blank=True) #and a few oth...

Django - argument of type 'WSGIRequest' is not iterable

How do you fix the following Django bug when working with forms? TypeError at /url/ argument of type 'WSGIRequest' is not iterable ...

Display a boolean model field in a django form as a radio button rather than the default Checkbox.

This is how I went about, to display a Boolean model field in the form as Radio buttons Yes and No. choices = ( (1,'Yes'), (0,'No'), ) class EmailEditForm(forms.ModelForm): #Display radio buttons instead of checkboxes to_send_form = forms.ChoiceField(choices=choices,widget=forms.RadioSelect) class Me...

How can I access the data in a Django form field form a view?

I have a simple Django Form: class testForm(forms.Form): list = forms.CharField() def getItems(self): #How do I do this? Access the data stored in list. return self.list.split(",") #This doesn't work The list form field stores a csv data value. From an external instance of testForm in a view, I want to be able to look a...

Allow changing of User fields (like email) with django-profiles

Django lets you create a model foreign-keyed to User and define it in settings as the official "profile" model holding additional data for user accounts. django-profiles lets you easily display/create/edit that profile data. But the user's primary email address is part of their main account, not part of their extended profile. Therefore ...

How to preset the username in Djangos login form?

After being dissatisfied with the existing solutions I wrote an OpenId provider for Django. If now somebody wants to authenticate himself somewhere as http://tejp.de/users/abc/ and needs to login for that, I want to display the login form with the username preset to "abc". The standard functions like redirect_to_login don't seem to prov...

storing file content in DB

I am making a model in which i have a filefield.I wan to store file content in the DB column instead of file path.ANy suggestions ...

Display full names in django form, not username

I have a Django app that has activities and objects that have foreign keys to the User object that is defined in django.contrib.auth.models. In doing this, I get the username property of the user, which is the login id. Since the User object stores the full name, how do I make a ChoiceField on an form display the full names of the user...

Django templates: verbose version of a choice

I have a model: from django.db import models CHOICES = ( ('s', 'Glorious spam'), ('e', 'Fabulous eggs'), ) class MealOrder(models.Model): meal = models.CharField(max_length=8, choices=CHOICES) I have a form: from django.forms import ModelForm class MealOrderForm(ModelForm): class Meta: model = MealOrder A...

Best way to make a model search form?

I have this model: class Aircraft(models.Model): model = models.CharField(max_length=64, blank=True) type = models.CharField(max_length=32) extra = models.CharField(max_length=32, blank=True) manufacturer = models.CharField(max_length=32) engine_type = models.IntegerField("Engine Type", choices=ENGINE_TYPE, default=0) cat_class...

Make Form Invalid without Raising ValidationError in Django

Hello, I would like a form to be invalid without raising a ValidationError in any of the form's or form's field's clean methods. The reason for this is that the form is the "super form" for a set of "sub forms", and I want the super form to be invalid when any of its subforms are invalid. But this invalidity does not entail raising a ...

Get POST data from a complex Django form?

I have a Django form that uses a different number of fields based on the year/month. So I create the fields in the form like this: for entry in entry_list: self.fields[entry] = forms.DecimalField([stuffhere]) but now I don't know how to get the submitted data from the form. Normally I would do something like: form.cleaned_data["...