Hello everyone,
I'm trying to create a form where users can save their progress. I have successfully managed to upload files when they are saved, but for some reason the following code leaves the file that was uploaded unbound from the form and thus making the user reupload the file:
class ImageForm(forms.ModelForm):
class Meta:
...
I've managed to get Django Forms to dynamically generate additional fields based on the relationship between a specific instance (eg. 'product type') and another model (eg. 'product attributes') eg. products have common attributes like weight and price but a book has a page count and a computer has specs.
I'd like to be able to do the s...
Here are the model definitions:
class ItemBrand(models.Model):
name = models.CharField(max_length = 30, unique = True)
def __unicode__(self):
return self.name
class WantedItem(models.Model):
name = models.CharField(max_length = 120)
description = models.TextField()
created = models.DateTimeField(auto_now = False, auto_now_add = Tr...
I use USStateField() from Django's localflavor in one of my models:
class MyClass(models.Model):
state = USStateField(blank=True)
Then I made a form from that class:
class MyClassForm(forms.ModelForm):
class Meta:
model = MyClass
When I display the form, the field "State" is a drop-down box with
"Alabama" pre-sel...
I have a model Calendar and in a form I want to be able to create multiple instances of it.
Here are my models:
class Event(models.Model):
user = models.ForeignKey(User)
class Group(models.Model):
name = models.CharField(_('Name'), max_length=80)
events = models.ManyToManyField(Event, through='Calendar')
class Calendar(mo...
I have a form with a ModelMultipleChoiceField() field. The form is used to send a message to user's friends. That means that instead of a generic queryset (e.g. Friends.objects.all()) I want to put something like queryset = user.friends.all().
Is this possible?
...
I'm rolling a custom comment app that can take any object and allow the user to post comments (much like the one that comes with django.contrib).
My first thought, since none of the form is specific to any particular view, was to put it in a template tag:
@register.inclusion_tag('comments/add.html', takes_context=True)
def add_comment(...
In Django login, we see a variable called "next" to redirect to the next page after login. How to control this variable?
...
Hi,
I'd like to display a number of forms via a ModelFormSet where each one of the forms displays in turn InlineFormSets for all objects connected to the object.
Now I'm not really sure how to provide the instances for each ModelFormSet. I thought about subclassing BaseModelFormSet but I have no clue on where to start and would like t...
I created a form class based on a model:
class MyModel(models.Model):
increasing_field = models.PositiveIntegerField()
class MyForm(forms.ModelForm):
class Meta:
model = MyModel
I created a form to change an existing MyClass instance using POST
data to populate the form:
m = MyModel.objects.get(pk=n)
f = MyForm(reque...
Hi all,
I'm using a Modelform for User to edit first_name and last_name, but I want an extra field from UserProfile (which has a 1-to-1 relation with User) added to this.
class UserProfileInfoForm(forms.ModelForm):
""" Profile Model field specifications for edit.
"""
class Meta:
model = User
fields = ('firs...
I want to create a search box in Django that is situated at the URL /search, and redirects to a friendly URL like /search/queryterm - rather than having ?q=queryterm in the URL)
So the user types in a query term, it takes them to /search/queryterm, and shows a list of results.
I can get and display the results OK given a URL like /sear...
Hello everyone,
I am attempting to validate a form (and it used to work before). For some reason, I can't seem to get the various cleaning functions such as clean_username(self) to get called when form.is_valid() is called.
I know there are not nearly enough checks yet (they are under construction you see ;-) ), but here are my classe...
Hi there
For my project I need many "workflow" forms. I explain myself:
The user selects a value in the first field, validates the form and new fields appear depending on the first field value. Then, depending on the others fields, new fields can appear...
How can I implement that in a generic way ?
...
I see a lot of people with Django apps that have image uploads are automatically resizing the images after they are uploaded. That is well and good for some cases, but I don't want to do this. Instead, I simply want to force the user to upload a file that is already the proper size.
I want to have an ImageField where I force the user t...
I am working with a file uploaded using Django's forms.FileField. This returns an object of type InMemoryUploadedFile.
I need to access this file in universal-newline mode. Any ideas on how to do this without saving and then reopening the file?
Thanks
...
I am using Django everyday now for three month and it is really great. Fast web application development.
I have still one thing that I cannot do exactly how I want to.
It is the SelectField and SelectMultiple Field.
I want to be able to put some args to an option of a Select.
I finally success with the optgroup :
class EquipmentField...
class Story(db.Model):
title = db.StringProperty(required=True)
slug = db.StringProperty(required=True)
I'm working with Django's forms on Google App Engine.
I want to automatically generate a slug from a user-submitted title -- and then I want to validate that it exists. The slug doesn't have to be unique, it just has to exis...
Django newbie question....
I'm trying to write a search form and maintain the state of the input box between the search request and the search results.
Here's my form:
class SearchForm(forms.Form):
q = forms.CharField(label='Search: ', max_length=50)
And here's my views code:
def search(request, q=""):
if (q != ""):
...
I have a modelchoicefield that has too many valid options to really show in a menu. How can I tell Django forms to use another widget that won't take up as much space rendering?
I want to use a HiddenField and I have another widget on the screen taht will populate it. If the hiddenfield has no value I keep getting form validation er...