Re: Django Model inheritance and foreignkeys

2009-11-01 Thread Andew Gee

That works great...thanks

bruno desthuilliers wrote:
> On 29 oct, 23:49, Andew Gee  wrote:
> > Hi,
> >
> > I have the following models
> >
> >     class Person(models.Model):
> >       name = models.CharField(max_length=100)
> >
> >     class Employee(Person):
> >       job = model.Charfield(max_length=200)
> >
> >     class PhoneNumber(models.Model):
> >       person = models.ForeignKey(Person)
> >
> > How do I access the PhoneNumbers associated with an employee if I have
> > the employee id?
> >
> > Currently I am using
> >
> > phones = PhoneNumbers.objects.filter(person__id=employee.id)
> >
>
> In  that case you not only have the employee id, you do have the whole
> employee instance, so you can just use employee.phonenumber_set.all()
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Django Model inheritance and foreignkeys

2009-10-29 Thread Andew Gee

Hi,

I have the following models

class Person(models.Model):
  name = models.CharField(max_length=100)

class Employee(Person):
  job = model.Charfield(max_length=200)

class PhoneNumber(models.Model):
  person = models.ForeignKey(Person)

How do I access the PhoneNumbers associated with an employee if I have
the employee id?

Currently I am using

phones = PhoneNumbers.objects.filter(person__id=employee.id)

and it works only because I know that the employee.id and person.id
are the same value, but I am sure this is the incorrect way to do
it.

Thanks
Andrew
--~--~-~--~~~---~--~~
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: Passing Parameter to form in inlineformset_factory

2009-10-25 Thread Andew Gee

Thanks for the help.

I did find this as a solution ad it seems to work

Formset = inlineformset_factory(ModelA, ModelB form=MyForm)
Formset.form = staticmethod(curry(MyForm, reaOnly=readOnlyvalue))
myFormset = Formset(request.Files, instance=modelAInst)

Regards
Andrew

Andew Gee wrote:
> Hi,
>
>
> I have the following Form defined
>
> class MyForm(ModelForm)
>
>   def __init__(self, readOnly=False, *args, **kwargs):
>   if readOnly:
>  Do stuff to make the inputs readonly
>
> MyForm works perfectly when I instantiate it in the view as a form
> form = MyForm(readOnly=True, instance=ModelA)
>
> but when I try to use it in the inlineformset_factory I get the error
>
> NoneType object is not callable.
>
> I know the problem id the way I am using the MyForm in the inline call
> because I get the same error if I do either of the following
>
> Formset = inlineformset_factory(ModelA, ModelB form=MyForm
> (readOnly=True))
> Formset = inlineformset_factory(ModelA, ModelB form=MyForm())
>
> but it works if I do
>
> Formset = inlineformset_factory(ModelA, ModelB form=MyForm)
>
> obviously the readOnly param defaults to False and my inputs are not
> changed.
>
> Does anyone know how I can pass the readOnly param to MyForm using the
> inlineformset_factory or how else I can achieve what I want?
>
> Thanks
> Andrew
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Passing Parameter to form in inlineformset_factory

2009-10-22 Thread Andew Gee

Hi,


I have the following Form defined

class MyForm(ModelForm)

  def __init__(self, readOnly=False, *args, **kwargs):
  if readOnly:
 Do stuff to make the inputs readonly

MyForm works perfectly when I instantiate it in the view as a form
form = MyForm(readOnly=True, instance=ModelA)

but when I try to use it in the inlineformset_factory I get the error

NoneType object is not callable.

I know the problem id the way I am using the MyForm in the inline call
because I get the same error if I do either of the following

Formset = inlineformset_factory(ModelA, ModelB form=MyForm
(readOnly=True))
Formset = inlineformset_factory(ModelA, ModelB form=MyForm())

but it works if I do

Formset = inlineformset_factory(ModelA, ModelB form=MyForm)

obviously the readOnly param defaults to False and my inputs are not
changed.

Does anyone know how I can pass the readOnly param to MyForm using the
inlineformset_factory or how else I can achieve what I want?

Thanks
Andrew


--~--~-~--~~~---~--~~
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: Dynamically add a line to an inlineformset

2009-08-22 Thread Andew Gee

Well...I don't know what happened but I have put my loop back in and
now it works. I cannot get the problem to reproduce. I must have had
something out of place but I don't know what, but it works now which
is what I need.

So again thanks for your help.

Andrew

On Aug 22, 7:27 pm, Andew Gee  wrote:
> I believe it wa the last of your suggestions, I was wrinting out the
> fields of the main form individually and somehow they must of been
> overwriting the inlineforms fields. I removed the loop that was doing
> the main form and just used the form object and it worked. So i need
> to go back and look over the fields to see why it was being
> overwritten.
>
> Thanks very much for your help.
>
> Andrew
>
> On Aug 22, 5:13 pm, Matthias Kestenholz
>
>  wrote:
> > On Sat, Aug 22, 2009 at 7:53 AM, Andew Gee wrote:
>
> > > Thank you for your help.
>
> > > I have managed to get the inlineforms to reproduce on my page, however
> > > when I submit the form the extra inlines are ignored. I have printed
> > > the formset when it hits the view and the new lines that I have added
> > > have no values in them, the values that I enter in are not being
> > > passed back by the request. Is this something that someone has seen
> > > before?
>
> > Yes, I've seen. It either means you are not correctly incrementing
> > TOTAL-FORMS (and therefore the formset code won't look at the added
> > parameters) or -- less probable -- you are not altering the name and
> > id attributes when creating new form rows. The second point is less
> > probable because you said that you can see the new fields on the
> > server side, even though you only see them as empty.
>
> > Another thing to check would be whether the said input fields exist
> > twice inside your form, and the later overwrite the former when the
> > browser is collecting the form fields' values.
>
> > Matthias
--~--~-~--~~~---~--~~
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: Dynamically add a line to an inlineformset

2009-08-22 Thread Andew Gee

I believe it wa the last of your suggestions, I was wrinting out the
fields of the main form individually and somehow they must of been
overwriting the inlineforms fields. I removed the loop that was doing
the main form and just used the form object and it worked. So i need
to go back and look over the fields to see why it was being
overwritten.

Thanks very much for your help.

Andrew

On Aug 22, 5:13 pm, Matthias Kestenholz
 wrote:
> On Sat, Aug 22, 2009 at 7:53 AM, Andew Gee wrote:
>
> > Thank you for your help.
>
> > I have managed to get the inlineforms to reproduce on my page, however
> > when I submit the form the extra inlines are ignored. I have printed
> > the formset when it hits the view and the new lines that I have added
> > have no values in them, the values that I enter in are not being
> > passed back by the request. Is this something that someone has seen
> > before?
>
> Yes, I've seen. It either means you are not correctly incrementing
> TOTAL-FORMS (and therefore the formset code won't look at the added
> parameters) or -- less probable -- you are not altering the name and
> id attributes when creating new form rows. The second point is less
> probable because you said that you can see the new fields on the
> server side, even though you only see them as empty.
>
> Another thing to check would be whether the said input fields exist
> twice inside your form, and the later overwrite the former when the
> browser is collecting the form fields' values.
>
> Matthias
--~--~-~--~~~---~--~~
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: Dynamically add a line to an inlineformset

2009-08-21 Thread Andew Gee

Thank you for your help.

I have managed to get the inlineforms to reproduce on my page, however
when I submit the form the extra inlines are ignored. I have printed
the formset when it hits the view and the new lines that I have added
have no values in them, the values that I enter in are not being
passed back by the request. Is this something that someone has seen
before?

Andrew

On Aug 21, 12:07 am, Noah  wrote:
> http://www.djangosnippets.org/snippets/1389/
>
> On Aug 20, 1:09 am, Matthias Kestenholz
>
>  wrote:
> > On Thu, Aug 20, 2009 at 7:27 AM, Andew Gee wrote:
>
> > > Does anyone know how to add a new line to anlineformset dynamically? I
> > > have a page that contains an inlineformset and I need to be able to
> > > click a button and add a new line which will then be saved when the
> > > form is submitted, is that possible?
>
> > Sure it is. Clone the HTML of the last line (or any empty line),
> > modifiy the id and name attributes (increment the counters by one) and
> > increment the TOTAL-FORMS hidden input field. There is no builtin
> > support for doing that in Django, because it is javascript framework
> > agnostic, but it's quite easy to do it anyway.
>
> > Maybe you find some inspiration how to do it in the admin-ui GSoC
> > branch? There, jQuery is used to provide exactly what you want.
>
> > Matthias
>
> > --
> > FeinCMS Django CMS building toolkit:http://spinlock.ch/pub/feincms/
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Dynamically add a line to an inlineformset

2009-08-19 Thread Andew Gee

Does anyone know how to add a new line to anlineformset dynamically? I
have a page that contains an inlineformset and I need to be able to
click a button and add a new line which will then be saved when the
form is submitted, is that possible?

Thanks
Andrew
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



How to use inlineformset with a manytomany relationship

2009-08-18 Thread Andew Gee

Hi,

Is there a way to create an inlineformset for two models with
manytomany relationship. I have created:

class Person(models.Model):
  name = models.CharField
  phone= models.ManyToMany(Phone)

class Phone(models.Model):
 PHONE_CHOICES(('H','Home'),('W",'Work'),('M','Mobile'))
 phone= models.CharField(max_length=10)
 phoneType = models.CharField(max_length=1,
choices=PHONE_CHOICES)

In my view I have
 PhoneFormSet = inlineformset_factory(Person, Phone)

but when I access the view I get the following error
  has no foreignkey to 

Is there something I have missed or do I need to setup my models
differently?

Thanks
Andrew
--~--~-~--~~~---~--~~
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: Formwizard and subforms

2009-08-17 Thread Andew Gee

That's a given. But thanks for your input, very helpful!

On Aug 18, 6:53 am, Wayne Koorts  wrote:
> > Nobody can help me with this?
>
> If somebody:
>
> a) Has the answer and,
> b) Has the time and,
> c) The inclination to provide the answer, then they will do so.
--~--~-~--~~~---~--~~
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: Formwizard and subforms

2009-08-17 Thread Andew Gee


Nobody can help me with this?


On Aug 15, 10:14 am, Gee  wrote:
> Hi,
>
> I am trying to build aformwizardthat includes a manytomany
> relationship on one of the steps and I am stuck on to implement the
> manytomany. The models are, (only for step in question)
>
> class Person(models.Model):
>       name = models.CharField
>       addr   = models.ManyToMany(Phone)
>
> class Phone(models.Model):
>      PHONE_CHOICES(('H','Home'),('W",'Work'),('M','Mobile'))
>      phone= models.CharField(max_length=10)
>      phoneType = models.CharField(max_length=1, choices=PHONE_CHOICES)
>
> The models are setup this way on the premise that more than one person
> could have any number of the same phone numbers.
>
> What I need to do is have a select box on the form that shows the
> phone choices and when one is selected an option to add a new line to
> the form that to retain that phone information for that type.
>
> Any help would be greatly appreciated.
>
> Thanks
> Andrew
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---