Re: Struggling with formsets

2015-02-19 Thread Werner Brand
Thanks for the reponse!  My template looks like this:


{{ formset.management_form }}

{{ formset }}

{% csrf_token %}

 

Here is the print request.POST:

form-1-salaryform-MAX_NUM_FORMSform-0-surnameform-0-nameform-TOTAL_FORMSform-MIN_NUM_FORMSform-0-idform-1-nameform-INITIAL_FORMScsrfmiddlewaretokenform-0-salaryform-1-idform-1-surname

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/74e6d086-5ec7-41f2-be04-edcf4f6d8aaa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Struggling with formsets

2015-02-19 Thread aRkadeFR

Hello,

Can we have the template?

Did you rendered the hidden fields id of your forms ?

Dump (by printing) the request.POST informations to see
if you received any "id" :)



On 02/19/2015 04:25 PM, Werner Brand wrote:
I cannot seem to figure this, although I suspects it is really 
elementary:


I have two models:

class Employee(models.Model):

id_number = models.CharField(max_length=13)

surname = models.CharField(max_length=100)

name =  models.CharField(max_length=100)


class Payslip(models.Model):

surname = models.CharField(max_length=100)
name =  models.CharField(max_length=100)

salary = models.DecimalField(max_digits=20, decimal_places=2)


In my forms:

class PayslipForm(ModelForm):

class Meta:

model = Payslip

fields = ['surname', 'name', 'salary']


PayslipFormSet = modelformset_factory(Payslip, extra=0)


In views.py:

def Payslip(request):

employee = Employee.objects.all()

formset = PayslipFormSet(queryset=employee)

context = {'formset': formset}

return render(request, 'file.html', context)


def PayslipSubmit(request):

f = PayslipFormSet(request.POST)

if f.is_valid():

f.save()

return HttpResponse('Submitted')

else:

return HttpResponse(f.errors)


The problem is that when I submit I get the following each form in 
formset:


  * id
  o Select a valid choice. That choice is not one of the available
choices.

I hope someone can help!

--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to django-users+unsubscr...@googlegroups.com 
.
To post to this group, send email to django-users@googlegroups.com 
.

Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8c766350-f426-475c-aac5-15f42952ce00%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


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


Struggling with formsets

2015-02-19 Thread Werner Brand
I cannot seem to figure this, although I suspects it is really elementary:

I have two models:

class Employee(models.Model):

id_number = models.CharField(max_length=13)

surname = models.CharField(max_length=100)

name =  models.CharField(max_length=100)


class Payslip(models.Model):

surname = models.CharField(max_length=100)
name =  models.CharField(max_length=100)

salary = models.DecimalField(max_digits=20, decimal_places=2)


In my forms:

class PayslipForm(ModelForm):

class Meta:

model = Payslip

fields = ['surname', 'name', 'salary']


PayslipFormSet = modelformset_factory(Payslip, extra=0)


In views.py:

def Payslip(request):

employee = Employee.objects.all()

formset = PayslipFormSet(queryset=employee)

context = {'formset': formset}

return render(request, 'file.html', context)


def PayslipSubmit(request):

f = PayslipFormSet(request.POST)

if f.is_valid():

f.save()

return HttpResponse('Submitted')

else:

return HttpResponse(f.errors) 


The problem is that when I submit I get the following each form in formset:

   - id
  - Select a valid choice. That choice is not one of the available 
  choices.
   
I hope someone can help!
 

 

 

 

 

 

 

 

 

 

 

 

 

 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8c766350-f426-475c-aac5-15f42952ce00%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Struggling with formsets

2012-05-29 Thread akaariai
On May 29, 12:45 pm, David 
wrote:
> Anyone else have any suggestions please?
>
> Thank you

I don't think there is a way to create formsets, and then formsets
related to the first formsets. So, something like this is what you
likely need:

for p in persons:
do_what_you_did_for_single_object() # remember to prefix the
forms.

I would likely do a list persons + their attendances view with edit
link/button for each person. That is one approach worth considering,
as it is pretty easy to do.

 - Anssi

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Struggling with formsets

2012-05-29 Thread David
Anyone else have any suggestions please?

Thank you

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/-8zgkyBbFBoJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Struggling with formsets

2012-05-18 Thread David
Thanks Pedesen for your reply.

I have tried inline-formsets and as you say unfortunately I could only get 
it to work with a single object.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/LVLBaUUdY8MJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Struggling with formsets

2012-05-18 Thread pedesen
For this case inline-formsets should be the way to go: 
https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#inline-formsets
But I think this will work for a particular person, but not for multiple 
persons...

Am Freitag, 18. Mai 2012 15:27:05 UTC+2 schrieb David:
>
> Given 2 models:
>
> class Person(models.Model):
> first_name = models.CharField(max_length=255)
> last_name = models.CharField(max_length=255)
>
> class PersonAttendance(models.Model):
> person = models.ForeignKey(Person)
> attend_date = models.DateField()
>
> I need to produce a formset that lists all Person(s) and their 
> PersonAttendance if it has been entered, and blank fields for Persons that 
> have no PersonAttendance related record so their attendance can be filled 
> in.
>
> In SQL I guess this would be achieved using a LEFT JOIN on Person, but I 
> can't work out how to get this working with the ORM and Django Formsets.
>
> Any help would be greatly appreciated, I've been stumped on this for ages.
>
> Thank you
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/aZuOiHNhGcEJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Struggling with formsets

2012-05-18 Thread David
Given 2 models:

class Person(models.Model):
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)

class PersonAttendance(models.Model):
person = models.ForeignKey(Person)
attend_date = models.DateField()

I need to produce a formset that lists all Person(s) and their 
PersonAttendance if it has been entered, and blank fields for Persons that 
have no PersonAttendance related record so their attendance can be filled 
in.

In SQL I guess this would be achieved using a LEFT JOIN on Person, but I 
can't work out how to get this working with the ORM and Django Formsets.

Any help would be greatly appreciated, I've been stumped on this for ages.

Thank you

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/2dRj9IjQwO4J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.