modelform

Django's ModelForm unique_together validation

旧巷老猫 提交于 2019-11-27 06:43:30
I have a Django model that looks like this. class Solution(models.Model): ''' Represents a solution to a specific problem. ''' name = models.CharField(max_length=50) problem = models.ForeignKey(Problem) description = models.TextField(blank=True) date = models.DateTimeField(auto_now_add=True) class Meta: unique_together = ("name", "problem") I use a form for adding models that looks like this: class SolutionForm(forms.ModelForm): class Meta: model = Solution exclude = ['problem'] My problem is that the SolutionForm does not validate Solution 's unique_together constraint and thus, it returns an

field choices() as queryset?

≡放荡痞女 提交于 2019-11-27 02:45:29
问题 I need to make a form, which have 1 select and 1 text input. Select must be taken from database. model looks like this: class Province(models.Model): name = models.CharField(max_length=30) slug = models.SlugField(max_length=30) def __unicode__(self): return self.name It's rows to this are added only by admin, but all users can see it in forms. I want to make a ModelForm from that. I made something like this: class ProvinceForm(ModelForm): class Meta: CHOICES = Province.objects.all() model =

How to get Interdependent dropdowns in django using Modelform and jquery?

 ̄綄美尐妖づ 提交于 2019-11-27 00:51:55
I am new to django and jquery. I am working on a django-based app where I have 3 drop downs in a form. 1. Campus 2. School 3. Centre The hierarchy is Campuses have schools and schools have centres. I want to interlink these drop-downs. For example, I have got 3 campuses, say Campus1, Campus2, Campus3. If I select Campus1, I should only get to select schools in campus1 and continuing this, if I select School1 then I need to be able to select centres of School1 and all other options should get hidden. I searched on net and have tried this http://blog.devinterface.com/2011/02/how-to-implement-two

Dynamically update ModelForm's Meta class

荒凉一梦 提交于 2019-11-26 23:53:47
问题 I am hoping to dynamically update a ModelForm's inline Meta class from my view. Although this code seems to update the exclude list in the Meta class, the output from as_p() , as_ul() , etc does not reflect the updated Meta exclude. I assume then that the html is generated when the ModelForm is created not when the as_*() is called. Is there a way to force the update of the HTML? Is this even the best way to do it? I just assumed this should work. Thoughts? from django.forms import ModelForm

Creating a model and related models with Inline formsets

大兔子大兔子 提交于 2019-11-26 21:18:55
[I have posted this at the Django users | Google Groups also.] Using the example in the inline formset docs , I am able to edit objects belonging a particular model (using modelforms). I have been trying to follow the same pattern for creating new objects using inline formsets, but have been unable to clear my head enough to bring out a working view for this purpose. Using the same example as in the above link, how would I go about creating a new instance of an "Author" model together with its related "Book" objects? priestc First, create a Author model form. author_form = AuthorModelForm()

Django's ModelForm unique_together validation

∥☆過路亽.° 提交于 2019-11-26 12:08:24
问题 I have a Django model that looks like this. class Solution(models.Model): \'\'\' Represents a solution to a specific problem. \'\'\' name = models.CharField(max_length=50) problem = models.ForeignKey(Problem) description = models.TextField(blank=True) date = models.DateTimeField(auto_now_add=True) class Meta: unique_together = (\"name\", \"problem\") I use a form for adding models that looks like this: class SolutionForm(forms.ModelForm): class Meta: model = Solution exclude = [\'problem\']

How to get Interdependent dropdowns in django using Modelform and jquery?

走远了吗. 提交于 2019-11-26 08:11:57
问题 I am new to django and jquery. I am working on a django-based app where I have 3 drop downs in a form. 1. Campus 2. School 3. Centre The hierarchy is Campuses have schools and schools have centres. I want to interlink these drop-downs. For example, I have got 3 campuses, say Campus1, Campus2, Campus3. If I select Campus1, I should only get to select schools in campus1 and continuing this, if I select School1 then I need to be able to select centres of School1 and all other options should get

Creating a model and related models with Inline formsets

放肆的年华 提交于 2019-11-26 07:54:42
问题 [I have posted this at the Django users | Google Groups also.] Using the example in the inline formset docs, I am able to edit objects belonging a particular model (using modelforms). I have been trying to follow the same pattern for creating new objects using inline formsets, but have been unable to clear my head enough to bring out a working view for this purpose. Using the same example as in the above link, how would I go about creating a new instance of an \"Author\" model together with