Re: [Django] #23404: Django modelformset returns the same data inserted in the previous insert when opening the same page for inserting new data

2014-09-03 Thread Django
#23404: Django modelformset returns the same data inserted in the previous 
insert
when opening the same page for inserting new data
-+-
 Reporter:  guruprasad   |Owner:  nobody
 Type:  Bug  |   Status:  closed
Component:  Forms|  Version:  1.6
 Severity:  Normal   |   Resolution:  invalid
 Keywords:   | Triage Stage:
  modelformset_factory   |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by timgraham):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 I think you need to look it `inlineformset_factory` and/or
 `BaseInlineFormSet`. As far as I can tell, `BaseModelFormSet` is working
 [https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#changing-
 the-queryset as documented].

--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.88cc2588440fe80cbe4ae3cfdc812fce%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #23404: Django modelformset returns the same data inserted in the previous insert when opening the same page for inserting new data

2014-09-03 Thread Django
#23404: Django modelformset returns the same data inserted in the previous 
insert
when opening the same page for inserting new data
-+-
 Reporter:  guruprasad   |Owner:  nobody
 Type:  Bug  |   Status:  new
Component:  Forms|  Version:  1.6
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:
  modelformset_factory   |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by guruprasad):

 Replying to [comment:2 timgraham]:
 > Any chance the browser is auto-populating the data from the last form
 fill? If not, this would be a pretty obvious bug so the problem is likely
 in your code although I don't see anything odd.

 Tim, I used pdb to render the html on the server side and it is having the
 data of all the fields in the model populated in the formset when it has
 to be rendered empty for a GET request. I tried it on a totally different
 codebase and app and I could see the same issue.

--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.5604587dee307a04ae286456fcbf0534%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #23404: Django modelformset returns the same data inserted in the previous insert when opening the same page for inserting new data

2014-09-03 Thread Django
#23404: Django modelformset returns the same data inserted in the previous 
insert
when opening the same page for inserting new data
-+-
 Reporter:  guruprasad   |Owner:  nobody
 Type:  Bug  |   Status:  new
Component:  Forms|  Version:  1.6
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:
  modelformset_factory   |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by timgraham):

 Any chance the browser is auto-populating the data from the last form
 fill? If not, this would be a pretty obvious bug so the problem is likely
 in your code although I don't see anything odd.

--
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.08d55aca6d4a8e9f7bbd2e157bbb2ad6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #23404: Django modelformset returns the same data inserted in the previous insert when opening the same page for inserting new data

2014-09-03 Thread Django
#23404: Django modelformset returns the same data inserted in the previous 
insert
when opening the same page for inserting new data
-+-
 Reporter:  guruprasad   |Owner:  nobody
 Type:  Bug  |   Status:  new
Component:  Forms|  Version:  1.6
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:
  modelformset_factory   |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by guruprasad):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Old description:

> {{{
> # models.py
> import datetime
>
> from django.db import models
>

> class Category(models.Model):
> category_name = models.CharField(unique=True, max_length=100)
> is_enabled = models.BooleanField(default=True)
> created_date = models.DateField(default=datetime.date.today)
>
> def __unicode__(self):
> return self.category_name
>
> class Website(models.Model):
> url = models.URLField(unique=True)
> site_name = models.CharField(max_length=100)
> vertical_category = models.ForeignKey(Category,
> related_name="websites")
> unique_users_per_day = models.IntegerField()
> page_views_per_day = models.IntegerField()
> unique_users_per_month = models.IntegerField()
> page_views_per_month = models.IntegerField()
>
> class Section(models.Model):
> website = models.ForeignKey(Website, related_name="sections")
> url = models.URLField(unique=True)
> section_name = models.CharField(max_length=100)
>
> }}}
>

> {{{
> # forms.py
> from django import forms
> from django.forms.models import modelformset_factory, BaseModelFormSet
> from .models import Website, Section
>

> class AddWebsiteForm(forms.ModelForm):
> def __init__(self, *args, **kwargs):
> super(AddWebsiteForm, self).__init__(*args, **kwargs)
> self.fields['unique_users_per_day'].widget = forms.TextInput()
> self.fields['page_views_per_day'].widget = forms.TextInput()
> self.fields['unique_users_per_month'].widget = forms.TextInput()
> self.fields['page_views_per_month'].widget = forms.TextInput()
> self.fields['vertical_category'].empty_label = "Vertical
> Category"
>
> class Meta:
> model = Website
> exclude = []
>

> class AddSectionForm(forms.ModelForm):
> class Meta:
> model = Section
> exclude = ['website',]
>

> class FirstRequiredFormSet(BaseModelFormSet):
> def __init__(self, *args, **kwargs):
> super(FirstRequiredFormSet, self).__init__(*args, **kwargs)
> for form in self.forms:
> form.empty_permitted = False
>
> AddSectionFormSet = modelformset_factory(Section, AddSectionForm,
> formset=FirstRequiredFormSet)
>
> }}}
>

> {{{
>
> from django.shortcuts import render, redirect
> from django.core.urlresolvers import reverse_lazy
> from django.forms.formsets import INITIAL_FORM_COUNT
>
> from .forms import AddWebsiteForm, AddSectionFormSet
>
> def add_website(request):
> import pdb; pdb.set_trace()
> if request.method == "POST":
>
> website_form = AddWebsiteForm(request.POST)
> section_formset = AddSectionFormSet(request.POST)
>
> if website_form.is_valid() and section_formset.is_valid():
> website = website_form.save()
> sections = section_formset.save(commit=False)
>
> for section in sections:
> section.website = website
> section.save()
>
> if 'add_another' in request.POST:
> return redirect(reverse_lazy('login'))
> else:
> return redirect(reverse_lazy('login'))
> else:
> website_form = AddWebsiteForm()
> section_formset = AddSectionFormSet()
>
> return render(request,
>   "website/add.html",
>   {
>   "website_form" : website_form,
>   "section_formset": section_formset
>   })
>
> }}}
>
> {{{
> 
> 
> {{ website_form }}
> 
> 
> {{ section_formset }}
> 
> 
>
> }}}
>
> After submitting the form for the first time and inserting some data, I
> visit the same URL for inserting more data. But the form of section
> formset is pre-populated with the data inserted the previous time.

New description:

 {{{
 # models.py
 import datetime

 from django.db import models


 class Category(models.Model):
 category_name = models.CharField(unique=True, max_length=100)
 is_enabled = models.BooleanField(default=True)
 creat