Re: Seeding Foreign Key with known object with Class Based Views

2012-11-27 Thread Lee Hinde
Thanks Sergi; I just realized my earlier response to you is still sitting
in my drafts folder.  This is helpful.



On Mon, Nov 26, 2012 at 12:08 AM, Sergiy Khohlov  wrote:

> I'm proposing  to add form_valid  function  and make  next trick
>
>
>  def form_valid(self, form)
>  # avoid to early savind od the new address
> newaddress  = form.save(commit=False)
># you need to update object by correct client id value. Keep in
> mind that I'm writing  without django from brain only :-)
> newaddress.client_id = self.client_data.id
># now  we are ready to save new address
> newaddress.save()
> return http.HttpResponseRedirect(self.get_success_url())
>
> 2012/11/25 Lee Hinde :
> >
> > On Nov 24, 2012, at 2:41 PM, Sergiy Khohlov  wrote:
> >
> >> I would like to clarify:
> >>
> >> 1) you dont need to add client id to the form
> >> (this value is already  set in your view)
> >>
> >> 2) If you dont know how to  save address let ask
> >> Of course please add your code. I can not hack your PC and understand
> >> your problem.
> >>
> >> thanks, Serge
> >> 2012/11/24 Lee Hinde :
> >>> nt to seed the client id programmatically without presenting a form
>  field to enter what's a known value
> >>
> >> --
> >
> >
> > Thanks for sticking with this.
> >
> > class AddressForm(ModelForm):
> > def __init__(self, *args, **kwargs):
> > super(AddressForm, self).__init__(*args, **kwargs)
> >
> > self.fields['city'].widget.attrs["class"] = 'capme'
> > self.fields['zip'].widget.attrs["class"] = 'zipcode'
> > self.fields['state'].widget.attrs["class"] = 'input-mini
> upper_case'
> >
> > class Meta:
> > model = Address
> > fields =
> ('street_one','street_two','city','state','zip','response_type')
> > exclude = ('client',)
> >
> >
> > class AddressNew(CreateView):
> > model = Address
> > template_name = 'letters/address.html'
> > form_class = AddressForm
> > context_object_name = 'myfields'
> >
> > def get(self, request, *args, **kwargs):
> > set_current_page(request, "", "active", "", "")
> > return super(AddressNew, self).get(request, *args, **kwargs)
> >
> > def get_context_data(self, **kwargs):
> > context = super(AddressNew, self).get_context_data(**kwargs)
> > context['client_data'] =
> get_object_or_404(Client,pk=self.kwargs["pk"])
> > return context
> >
> >
> > Then, in the template I'm putting client_data.id into a hidden field to
> be returned when the form is saved.
> >
> >
> > --
> > 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.
> >
>
> --
> 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.
>
>

-- 
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: Seeding Foreign Key with known object with Class Based Views

2012-11-26 Thread Sergiy Khohlov
I'm proposing  to add form_valid  function  and make  next trick


 def form_valid(self, form)
 # avoid to early savind od the new address
newaddress  = form.save(commit=False)
   # you need to update object by correct client id value. Keep in
mind that I'm writing  without django from brain only :-)
newaddress.client_id = self.client_data.id
   # now  we are ready to save new address
newaddress.save()
return http.HttpResponseRedirect(self.get_success_url())

2012/11/25 Lee Hinde :
>
> On Nov 24, 2012, at 2:41 PM, Sergiy Khohlov  wrote:
>
>> I would like to clarify:
>>
>> 1) you dont need to add client id to the form
>> (this value is already  set in your view)
>>
>> 2) If you dont know how to  save address let ask
>> Of course please add your code. I can not hack your PC and understand
>> your problem.
>>
>> thanks, Serge
>> 2012/11/24 Lee Hinde :
>>> nt to seed the client id programmatically without presenting a form
 field to enter what's a known value
>>
>> --
>
>
> Thanks for sticking with this.
>
> class AddressForm(ModelForm):
> def __init__(self, *args, **kwargs):
> super(AddressForm, self).__init__(*args, **kwargs)
>
> self.fields['city'].widget.attrs["class"] = 'capme'
> self.fields['zip'].widget.attrs["class"] = 'zipcode'
> self.fields['state'].widget.attrs["class"] = 'input-mini upper_case'
>
> class Meta:
> model = Address
> fields = 
> ('street_one','street_two','city','state','zip','response_type')
> exclude = ('client',)
>
>
> class AddressNew(CreateView):
> model = Address
> template_name = 'letters/address.html'
> form_class = AddressForm
> context_object_name = 'myfields'
>
> def get(self, request, *args, **kwargs):
> set_current_page(request, "", "active", "", "")
> return super(AddressNew, self).get(request, *args, **kwargs)
>
> def get_context_data(self, **kwargs):
> context = super(AddressNew, self).get_context_data(**kwargs)
> context['client_data'] = 
> get_object_or_404(Client,pk=self.kwargs["pk"])
> return context
>
>
> Then, in the template I'm putting client_data.id into a hidden field to be 
> returned when the form is saved.
>
>
> --
> 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.
>

-- 
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: Seeding Foreign Key with known object with Class Based Views

2012-11-24 Thread Lee Hinde

On Nov 24, 2012, at 2:41 PM, Sergiy Khohlov  wrote:

> I would like to clarify:
> 
> 1) you dont need to add client id to the form
> (this value is already  set in your view)
> 
> 2) If you dont know how to  save address let ask
> Of course please add your code. I can not hack your PC and understand
> your problem.
> 
> thanks, Serge
> 2012/11/24 Lee Hinde :
>> nt to seed the client id programmatically without presenting a form
>>> field to enter what's a known value
> 
> -- 


Thanks for sticking with this.

class AddressForm(ModelForm):
def __init__(self, *args, **kwargs):
super(AddressForm, self).__init__(*args, **kwargs)

self.fields['city'].widget.attrs["class"] = 'capme'
self.fields['zip'].widget.attrs["class"] = 'zipcode'
self.fields['state'].widget.attrs["class"] = 'input-mini upper_case'

class Meta:
model = Address
fields = 
('street_one','street_two','city','state','zip','response_type')
exclude = ('client',)


class AddressNew(CreateView):
model = Address
template_name = 'letters/address.html'
form_class = AddressForm
context_object_name = 'myfields'

def get(self, request, *args, **kwargs):
set_current_page(request, "", "active", "", "")
return super(AddressNew, self).get(request, *args, **kwargs)

def get_context_data(self, **kwargs):
context = super(AddressNew, self).get_context_data(**kwargs)
context['client_data'] = get_object_or_404(Client,pk=self.kwargs["pk"])
return context


Then, in the template I'm putting client_data.id into a hidden field to be 
returned when the form is saved.


-- 
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: Seeding Foreign Key with known object with Class Based Views

2012-11-24 Thread Sergiy Khohlov
I would like to clarify:

1) you dont need to add client id to the form
(this value is already  set in your view)

2) If you dont know how to  save address let ask
 Of course please add your code. I can not hack your PC and understand
your problem.

 thanks, Serge
2012/11/24 Lee Hinde :
> nt to seed the client id programmatically without presenting a form
>> field to enter what's a known value

-- 
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: Seeding Foreign Key with known object with Class Based Views

2012-11-24 Thread Lee Hinde
Thanks, but that bit of docs shows that there can be a relationship between
models, but doesn't answer the question I was trying to ask which is, how
to create the relationship in data.


On Thu, Nov 22, 2012 at 12:31 AM, Sergiy Khohlov  wrote:

>
> https://docs.djangoproject.com/en/dev/topics/class-based-views/generic-display/
>  switch  Publisher to client  and  books to address
>  :-)
>
> 2012/11/22 Lee Hinde :
> > I have two tables, Client and Address. Address has a foreign key 'client'
> > which points to the client table. I'll make my user enter a client and
> then
> > enter 1-x Addresses. I'll know which client the address is being linked
> to
> > before the record is created, with a url like : /client/3/address/new/.
> >
> > I want to seed the client id programmatically without presenting a form
> > field to enter what's a known value.
> >
> > I've got this working with method based views, (just throw the client id
> in
> > a hidden field. easy peasy) but can't find an example for what seems to
> me
> > to be a real common need using class based views.
> >
> > The closest I've found are examples relating a user to an object, but
> this
> > isn't quite that and I've spent a fair amount of time trying to adapt the
> > example and either the form complains because the client field is
> missing or
> > there's some other problem.
> >
> > Sooo, I'm hoping that there's an existing example/blog post/stackoverflow
> > question that I've missed that someone could point me to that
> demonstrates
> > this process.
> >
> > Thanks and happy thanksgiving for us US residents. I'll be thankful for
> the
> > non-US folk who might be working and would care to take a shot at this.
> >
> > --
> > 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.
>
> --
> 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.
>
>

-- 
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: Seeding Foreign Key with known object with Class Based Views

2012-11-22 Thread Sergiy Khohlov
https://docs.djangoproject.com/en/dev/topics/class-based-views/generic-display/
 switch  Publisher to client  and  books to address
 :-)

2012/11/22 Lee Hinde :
> I have two tables, Client and Address. Address has a foreign key 'client'
> which points to the client table. I'll make my user enter a client and then
> enter 1-x Addresses. I'll know which client the address is being linked to
> before the record is created, with a url like : /client/3/address/new/.
>
> I want to seed the client id programmatically without presenting a form
> field to enter what's a known value.
>
> I've got this working with method based views, (just throw the client id in
> a hidden field. easy peasy) but can't find an example for what seems to me
> to be a real common need using class based views.
>
> The closest I've found are examples relating a user to an object, but this
> isn't quite that and I've spent a fair amount of time trying to adapt the
> example and either the form complains because the client field is missing or
> there's some other problem.
>
> Sooo, I'm hoping that there's an existing example/blog post/stackoverflow
> question that I've missed that someone could point me to that demonstrates
> this process.
>
> Thanks and happy thanksgiving for us US residents. I'll be thankful for the
> non-US folk who might be working and would care to take a shot at this.
>
> --
> 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.

-- 
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.



Seeding Foreign Key with known object with Class Based Views

2012-11-21 Thread Lee Hinde
I have two tables, Client and Address. Address has a foreign key 'client'
which points to the client table. I'll make my user enter a client and then
enter 1-x Addresses. I'll know which client the address is being linked to
before the record is created, with a url like : /client/3/address/new/.

I want to seed the client id programmatically without presenting a form
field to enter what's a known value.

I've got this working with method based views, (just throw the client id in
a hidden field. easy peasy) but can't find an example for what seems to me
to be a real common need using class based views.

The closest I've found are examples relating a user to an object, but this
isn't quite that and I've spent a fair amount of time trying to adapt the
example and either the form complains because the client field is missing
or there's some other problem.

Sooo, I'm hoping that there's an existing example/blog post/stackoverflow
question that I've missed that someone could point me to that demonstrates
this process.

Thanks and happy thanksgiving for us US residents. I'll be thankful for the
non-US folk who might be working and would care to take a shot at this.

-- 
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.