Re: Django or python question about classes

2011-11-30 Thread youpsla
Thanks for the link Tom.

I'll read that in details later (it's a little bit complicated) an for
my POC I'll just use a not DRY method !!! :-)

Regards

Youpsla

On 28 nov, 17:16, Tom Evans <tevans...@googlemail.com> wrote:
> On Mon, Nov 28, 2011 at 4:07 PM, youpsla <youp...@gmail.com> wrote:
> > Hello,
> > in my code, I like to overrride the form_valid() method in both
> > CreateView and UpdateView generic class views.
>
> > I've put my code in views.py.
>
> > class MyCreateView(UpdateView):
> >    .
> >    def form_valid(self, form, **kwargs):
> >        some code
>
> > class MyUpdateView(CreateView):
> >    .
> >    def form_valid(self, form, **kwargs):
> >        some code
>
> > The both form_valid() methods are exactly the same (Only the
> > dispatch() method differ from both classes).
>
> > My question is : is there a way of doing this more in a DRY way ?
>
> > Thanks in advance.
>
> > Best regards
>
> > Alain
>
> http://stackoverflow.com/questions/533631/what-is-a-mixin-and-why-are...
>
> Cheers
>
> Tom

-- 
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 or python question about classes

2011-11-28 Thread youpsla
Hello,
in my code, I like to overrride the form_valid() method in both
CreateView and UpdateView generic class views.

I've put my code in views.py.

class MyCreateView(UpdateView):
.
def form_valid(self, form, **kwargs):
some code

class MyUpdateView(CreateView):
.
def form_valid(self, form, **kwargs):
some code

The both form_valid() methods are exactly the same (Only the
dispatch() method differ from both classes).

My question is : is there a way of doing this more in a DRY way ?

Thanks in advance.

Best regards

Alain

-- 
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: Reverse and variables in template

2011-11-24 Thread youpsla
Thnaks a lots,
it works.

Youpsla

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



Reverse and variables in template

2011-11-24 Thread youpsla
Hello,

The following line in my template return an error:
Modifier

Error is:

Could not parse the remainder: '{{' from '{{'


If i use (has view in the doc):

Modifier

it works fine.


Then is the syntax {% url url_name {{model.field}} %} allowed ?


Somebody has an idea ?


Thanks for your precious help.


Regards


youpsla

-- 
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/-/1IxshdRdwksJ.
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: 'function' object has no attribute 'as_view'

2011-11-23 Thread youpsla
Thanks for all.

Agai I apologize for not having post this "etail" in my originl post.

Regards

Alain

-- 
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/-/cvt5qYYGgDsJ.
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: 'function' object has no attribute 'as_view'

2011-11-23 Thread youpsla
Hello all,
I've verified that I don't override the class.

I've found the reason of the bug. When I delete "@login_required", it works.

My class was in view.py:

@login_required
class EvenementCreateView(.):
.


I apologize for not have copy/paste that in my first post.

I've done the test with another class, it's the same. Then I 
think @login_required works only for function and not for Class.

I don't know what happend internally ... But for now it's ok for me. I'm 
building the POC. But for production purpose, it will be an issue.



Thanks all for your time.

Regards

Alain

-- 
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/-/Fz84rqy-ANwJ.
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: 'function' object has no attribute 'as_view'

2011-11-23 Thread youpsla
Hi again,
yes I'm sure the error comes from here. Bellow is the full trace back:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8010/magasin/

Django Version: 1.3.1
Python Version: 2.7.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'south',
 'clients',
 'django.contrib.admin',
 'categories',
 'magasins',
 'registration',
 'profiles',
 'evenements',
 'commandes',
 'debug_toolbar']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware')


Traceback:
File "C:\Python27\Lib\site-packages\django\core\handlers\base.py" in 
get_response
  89. response = middleware_method(request)
File "C:\Python27\Lib\site-packages\debug_toolbar\middleware.py" in 
process_request
  70. original_urlconf = __import__(getattr(request, 
'urlconf', settings.ROOT_URLCONF), {}, {}, ['*'])
File "C:\dev\Flash\urls.py" in 
  25. (r'magasin/(?P\d+)/evenement/new/$', 
EvenementCreateView.as_view(model=Evenement)),

Exception Type: AttributeError at /magasin/
Exception Value: 'function' object has no attribute 'as_view'


Any ideas are welcome, because this error let me dry !!! h


Regards

Alain

-- 
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/-/Ijq8McV21HQJ.
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: 'function' object has no attribute 'as_view'

2011-11-23 Thread youpsla
Hi,
thnaks for your answer. It's the same. it doesn't work.

For information I use generic view for other part of the site with:
url(r"magasin/(?P\d+)/supprimer/$", DeleteView.as_view(model=Magasin, 
success_url="/magasins/liste"), name='magasin_supprimer'),

and it works fine.

And has you say, django seems to believe that EvenementCreateView from 
views.py is a function, but the declaration is:
class EvenementCreateView(CreateView):
.

That's what I dont understand.

I use the same schema for other part and it works fine. I've read my code 
caracter after caracter to compare  it looks very very similar 


Still a mystery for me. 

Again, thanks for your answer


Alain

-- 
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/-/0Tg6RPA34W8J.
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.



'function' object has no attribute 'as_view'

2011-11-23 Thread youpsla
Hello,
the issue here seems to be trivial, maybe I got something in my eyes,
but I can't find the solution.

Here is my code:

urls.py
url(r"magasin/(?P\d+)/evenement/new/$",
EvenementCreateView.as_view(model=Evenement),
name='new_evenement_magasin'),

views.py:
class EvenementCreateView(CreateView):
form_class = EvenementForm
sucess_url = 'user_magasins'

def dispatch(self, *args, **kwargs):
   bla bla bla 

def form_valid(self, form):
   bl bla bla .
   return HttpResponseRedirect(self.get_success_url())


What is funny here is whatever url of the site I call, even one which
doesn't use this view I've the error describe in the subject. The
traceback point on the line of the urls.py.

I'm not python and django proof, but as far I know class blablabla()
define a Class and not a function !!!

Does someone have an idea here ?

Regards

Alain

-- 
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: Manage exception from external services in a form

2011-11-15 Thread youpsla
Sorry,

I've not search enough,

I think this post : 
http://stackoverflow.com/questions/6365318/custom-field-error-from-try-except-in-django-view

give me the solution . but one question left, can I do this
solution in the form_valid part of my class ... I'll try ...

Regards

Alain

On 16 nov, 05:08, youpsla <youp...@gmail.com> wrote:
> Hello,
> I hope, despite my poor english, to be enough clear.
>
> In my Django app, users fill a form with adress, Zip, CIty
> informations.
>
> I like to geocode those informations to fill the lat and lng field of
> the table db. FOt this tak I use geocoders method from geopy module.
> It works fine if Google doesn't raise an error.
>
> If I got an error ("GQueryError"), I like my Django app refresh to the
> form page (Has it's the case for example in case of an empty field
> with no blank=True option) and show an error message to the user
> explaining him I can't geocode him blablabla 
>
> My App is organize like this:
>
> - A model with all fields I talk about above
> - I use the generic base view (CreateView)
> - The geocoding take place in the form_valid(self,form) function in my
> pesonnal overriding class of CreateView.
>
> Hope there is enough informations  .
>
> Help will be really appreciated. Of course feel free to ask all
> informations you want.
>
> Regards
>
> Alain

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



Manage exception from external services in a form

2011-11-15 Thread youpsla
Hello,
I hope, despite my poor english, to be enough clear.

In my Django app, users fill a form with adress, Zip, CIty
informations.

I like to geocode those informations to fill the lat and lng field of
the table db. FOt this tak I use geocoders method from geopy module.
It works fine if Google doesn't raise an error.

If I got an error ("GQueryError"), I like my Django app refresh to the
form page (Has it's the case for example in case of an empty field
with no blank=True option) and show an error message to the user
explaining him I can't geocode him blablabla 


My App is organize like this:

- A model with all fields I talk about above
- I use the generic base view (CreateView)
- The geocoding take place in the form_valid(self,form) function in my
pesonnal overriding class of CreateView.

Hope there is enough informations  .

Help will be really appreciated. Of course feel free to ask all
informations you want.

Regards

Alain


-- 
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: Project general design question - "From scratch" or use of admin interface

2011-11-07 Thread youpsla
Ok,
thanks for the answer,then I'll start this way.

Just another question. I'll use a registration package I think for
Shops owners, do you know wich one could be the best for jsut a simple
registration workflow ?


Agian, thnaks for your time

Regards

Alain

On 7 nov, 13:32, Russell Keith-Magee <russ...@keith-magee.com> wrote:
> On Mon, Nov 7, 2011 at 8:06 PM, youpsla <youp...@gmail.com> wrote:
> > Hi,
> > before getting more in depth in writing my project I ask you a general
> > design question. My Django knowledge is not BIG enough for me to be
> > able to have a clear answer (with for and cons) on my question.
>
> > Here are the main guidelines of my project :
> > - I've two kind of users : Shop owners and consumers (I've already don
> > the part for consumers wich is quite simple)
> > - Shop owners have to register (Simple workflow : Email send with a
> > link for confirmation and activation)
> > - I like shops owners to be able to:
> >    - Create one ore more shops with some informations (Adress, openg/
> > closing time etc )
> >    - For each shop, they can add events
> >    - Of course each shops owner can only access to shops and events
> > he has created himself
>
> > My question, is:
> > Do you thing it's better to use and customize the admin interface or
> > it's better to write all "from scratch".
>
> Generally speaking, you're going to want to do it "from scratch".
>
> The admin interface isn't intended to be a framework for building your
> site. It's exactly what it says on the box -- an administration
> interface. It presents a very low-level view of your database, which
> is handy for tweaking data at a low level, but it isn't really suited
> to public facing sites.
>
> If you have requirements that involve customized workflows, or you're
> expecting to customize views or structure, you're going to be better
> served by building the site from scratch.
>
> That said, Django doesn't leave you completely to your own devices.
> Most websites have, at their core, lots of fairly common functionality
> -- show me a list of all available X objects; show me the details for
> widget 3; allow me to edit the details for widget 3, and so on.
>
> This is where Django's generic views come in. The generic views are
> pre-canned views for displaying and editing objects in common ways. If
> you're looking to bang out a proof of concept, you'd be much better
> suited to spending your time working out how to use generic views,
> rather than trying to work out how to bend the admin to your will.
>
> Yours,
> Russ Magee %-)

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



Project general design question - "From scratch" or use of admin interface

2011-11-07 Thread youpsla
Hi,
before getting more in depth in writing my project I ask you a general
design question. My Django knowledge is not BIG enough for me to be
able to have a clear answer (with for and cons) on my question.

Here are the main guidelines of my project :
- I've two kind of users : Shop owners and consumers (I've already don
the part for consumers wich is quite simple)
- Shop owners have to register (Simple workflow : Email send with a
link for confirmation and activation)
- I like shops owners to be able to:
- Create one ore more shops with some informations (Adress, openg/
closing time etc )
- For each shop, they can add events
- Of course each shops owner can only access to shops and events
he has created himself

My question, is:
Do you thing it's better to use and customize the admin interface or
it's better to write all "from scratch".

My goal here is to setup a POOF and not necessary is project wich can
handle millions of hits :-)


Feel free to ask further information if needed.

Thanks in advance for your time.


Alain

-- 
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 - Many2Many field - instance needs to have a primary key value before a many-to-many relationship can be used

2011-11-02 Thread youpsla
Thanks Furbee,

UNDERSTOOD.

Thanks again for detailled and instructive answers.

Alain

On 2 nov, 21:36, Furbee <furbeena...@gmail.com> wrote:
> Hi Alain,
>
> Sort of. With this code:
>     if field == 'category':
>         instance.save()
> a Customer with 50 categories would write to the database 51 times (1
> INSERT, and 50 UPDATES).
>
> Including the "instance.id == None" like this:
>     if field == 'category' and instance.id == None:
>         instance.save()
> will make it write to the database one or two times maximum. If the
> Customer has 0 categories, it will write once (INSERT at bottom of
> program). If the Customer has n categories, it will only write once
> (INSERT) in the loops, and write once (UPDATE) at the bottom of the program.
>
> That is why it is much quicker running it this way.
>
> Cheers,
>
> Furbeenator
>
>
>
>
>
>
>
> On Wed, Nov 2, 2011 at 1:00 PM, youpsla <youp...@gmail.com> wrote:
> > Hi again
> > thanks for explanations.
>
> > I've understood difference between Null and None.
>
> > I've modify the code to add "instance.id == Non" and it seems to be
> > faster.
>
> > To be sure. You mean that if a customer has 1 category, there will be
> > 2 database access (one for all informations except category and one
> > for category).
>
> > If a customer has 50 categories, then it's 51 database access ? hu
>
> > Thanks again
>
> > Alain
>
> > On 2 nov, 20:11, Furbee <furbeena...@gmail.com> wrote:
> > > Hi Alain,
>
> > > Glad that it worked out! :-)
>
> > > To clarify, a blank is different from a Null, or "None" in
> > Python/Django. A
> > > blank character field is "" where a null character field is NULL. If a
> > > field does not specify null=True, and you try to save an instance of that
> > > object without specifying that field, it will raise a Database error. So,
> > > in your loop if you hit category first, before any other fields, it would
> > > try to save the instance of the Customer without specifying all of the
> > > fields needed. That is why category must come AFTER all other fields that
> > > are required (not null=True).
>
> > > You are correct. The instance = Customer() creates a new customer object,
> > > when you executed instance.save() the instance information is saved
> > > (INSERT) to the database, and it received a PK (id). Every subsequent
> > > instance.save() actually runs (UPDATE) on the database, updating all
> > fields
> > > in the instance. If you have a whole lot of fields in the Customer, one
> > > optimization would be to add logic to the loop that if the field is
> > > 'category' and the instance has not yet been saved, save it. This way it
> > is
> > > only saved once before adding category and once at the end of setting all
> > > attributes. This will probably be a better solution, and will hit the
> > > database only twice instead of +1 times:
>
> > > class InscriptionWizard(SessionWizardView):
> > >     def done(self, form_list, **kwargs):
> > >         instance = Customer()
> > >         for form in form_list:
> > >             for field, value in form.cleaned_data.iteritems():
> > >                 if field == 'category' and instance.id == None: # if
> > this
> > > is a category, and the instance has not yet been saved, save it so it has
> > > an id.
> > >                     instance.save()
> > >                 setattr(instance, field, value)
> > >         instance.save()
>
> > > Happy coding!
>
> > > Furbeenator
>
> > > On Wed, Nov 2, 2011 at 12:00 PM, youpsla <youp...@gmail.com> wrote:
> > > > Oupsss, another question in the step by step:
>
> > > > 1 class InscriptionWizard(SessionWizardView):
> > > > 2    def done(self, form_list, **kwargs):
> > > > 3        instance = Customer()
> > > > 4        for form in form_list:
> > > > 5            for field, value in form.cleaned_data.iteritems():
> > > > 6                if field == 'category':
> > > > 7                    instance.save()
> > > > 8                setattr(instance, field, value)
> > > > 9        instance.save()
>
> > > > Line 7 : Will save in the DB all fields that have been already
> > > > iterated. Then I suppose the instance.save() will not clear
> > > > informations affected by the setattr() otherwise the PK is lost ...
> > 

Re: Formwizard - Many2Many field - instance needs to have a primary key value before a many-to-many relationship can be used

2011-11-02 Thread youpsla
Hi again
thanks for explanations.

I've understood difference between Null and None.

I've modify the code to add "instance.id == Non" and it seems to be
faster.

To be sure. You mean that if a customer has 1 category, there will be
2 database access (one for all informations except category and one
for category).

If a customer has 50 categories, then it's 51 database access ? hu


Thanks again

Alain



On 2 nov, 20:11, Furbee <furbeena...@gmail.com> wrote:
> Hi Alain,
>
> Glad that it worked out! :-)
>
> To clarify, a blank is different from a Null, or "None" in Python/Django. A
> blank character field is "" where a null character field is NULL. If a
> field does not specify null=True, and you try to save an instance of that
> object without specifying that field, it will raise a Database error. So,
> in your loop if you hit category first, before any other fields, it would
> try to save the instance of the Customer without specifying all of the
> fields needed. That is why category must come AFTER all other fields that
> are required (not null=True).
>
> You are correct. The instance = Customer() creates a new customer object,
> when you executed instance.save() the instance information is saved
> (INSERT) to the database, and it received a PK (id). Every subsequent
> instance.save() actually runs (UPDATE) on the database, updating all fields
> in the instance. If you have a whole lot of fields in the Customer, one
> optimization would be to add logic to the loop that if the field is
> 'category' and the instance has not yet been saved, save it. This way it is
> only saved once before adding category and once at the end of setting all
> attributes. This will probably be a better solution, and will hit the
> database only twice instead of +1 times:
>
> class InscriptionWizard(SessionWizardView):
>     def done(self, form_list, **kwargs):
>         instance = Customer()
>         for form in form_list:
>             for field, value in form.cleaned_data.iteritems():
>                 if field == 'category' and instance.id == None: # if this
> is a category, and the instance has not yet been saved, save it so it has
> an id.
>                     instance.save()
>                 setattr(instance, field, value)
>         instance.save()
>
> Happy coding!
>
> Furbeenator
>
>
>
>
>
>
>
> On Wed, Nov 2, 2011 at 12:00 PM, youpsla <youp...@gmail.com> wrote:
> > Oupsss, another question in the step by step:
>
> > 1 class InscriptionWizard(SessionWizardView):
> > 2    def done(self, form_list, **kwargs):
> > 3        instance = Customer()
> > 4        for form in form_list:
> > 5            for field, value in form.cleaned_data.iteritems():
> > 6                if field == 'category':
> > 7                    instance.save()
> > 8                setattr(instance, field, value)
> > 9        instance.save()
>
> > Line 7 : Will save in the DB all fields that have been already
> > iterated. Then I suppose the instance.save() will not clear
> > informations affected by the setattr() otherwise the PK is lost ...
> > and the Line 9 doesn't know wich PK to use 
>
> > Then I suppose the Line 9 will save all informations of the form,
> > those which have been already saved by Line 7 and add category. Then I
> > suppose Django will perform an "UPDATE" rather than an "INSERT" SQL
> > statement ?
>
> > Is it right ?
>
> > Again, regards for the time spend to answer.
>
> > Alain
>
> > On 2 nov, 19:03, Furbee <furbeena...@gmail.com> wrote:
> > > In your Customer model there are fields which cannot be Null, so you
> > cannot
> > > instance.save() before setting those properties. So, you may have to
> > check
> > > for the category field in your loop and if it is category, save the
> > > instance first. Something like the following:
>
> > > views.py (in clients application)
> > > -
> > > class InscriptionWizard(SessionWizardView):
> > >    def done(self, form_list, **kwargs):
> > >        instance = Customer()
> > >        for form in form_list:
> > >            for field, value in form.cleaned_data.iteritems():
> > >                if field == 'category':
> > >                    instance.save()
> > >                setattr(instance, field, value)
> > >        instance.save()
> > > -
>
> > > This would of course depend on your ordering of the fields. In other
> > words,
> > 

Re: Formwizard - Many2Many field - instance needs to have a primary key value before a many-to-many relationship can be used

2011-11-02 Thread youpsla
Oupsss, another question in the step by step:

1 class InscriptionWizard(SessionWizardView):
2    def done(self, form_list, **kwargs):
3        instance = Customer()
4        for form in form_list:
5            for field, value in form.cleaned_data.iteritems():
6                if field == 'category':
7                    instance.save()
8                setattr(instance, field, value)
9        instance.save()

Line 7 : Will save in the DB all fields that have been already
iterated. Then I suppose the instance.save() will not clear
informations affected by the setattr() otherwise the PK is lost ...
and the Line 9 doesn't know wich PK to use 

Then I suppose the Line 9 will save all informations of the form,
those which have been already saved by Line 7 and add category. Then I
suppose Django will perform an "UPDATE" rather than an "INSERT" SQL
statement ?

Is it right ?


Again, regards for the time spend to answer.

Alain

On 2 nov, 19:03, Furbee <furbeena...@gmail.com> wrote:
> In your Customer model there are fields which cannot be Null, so you cannot
> instance.save() before setting those properties. So, you may have to check
> for the category field in your loop and if it is category, save the
> instance first. Something like the following:
>
> views.py (in clients application)
> -
> class InscriptionWizard(SessionWizardView):
>    def done(self, form_list, **kwargs):
>        instance = Customer()
>        for form in form_list:
>            for field, value in form.cleaned_data.iteritems():
>                if field == 'category':
>                    instance.save()
>                setattr(instance, field, value)
>        instance.save()
> -
>
> This would of course depend on your ordering of the fields. In other words,
> category would have to be the first Allow Null field in your model, because
> you cannot save() until all Not Null fields have a value. If you cannot
> order these fields so the category is last, you may have to do something
> like:
>
> views.py (in clients application)
> -
> class InscriptionWizard(SessionWizardView):
>    def done(self, form_list, **kwargs):
>        instance = Customer()
>        for form in form_list:
>            for field, value in form.cleaned_data.iteritems():
>                if field != 'category':
>                    setattr(instance, field, value)
>        instance.save()
>        for form in form_list:
>            for field, value in form.cleaned_data.iteritems():
>                if field == 'category':
>                    setattr(instance, field, value)
> -
>
> I'm sure there is a MUCH more elegant way of getting just the categories
> from the forms and field/value pairs, this is brute force (not very
> scalable for large number of fields), but should work. Anybody else please,
> show code that could get the specific forms and field/values for categories.
>
> Furbeenator
>
>
>
>
>
>
>
> On Wed, Nov 2, 2011 at 10:28 AM, youpsla <youp...@gmail.com> wrote:
> > Hello,
> > i'm currently doning a website where user can register (without
> > password, without auth module of Django). They put some informations
> > and at the end (Step5Form) do multiple choices by clicking on
> > checkboxes. When I click on validate on the last step I've "instance
> > needs to have a primary key value before a many-to-many relationship
> > can be used" error. I've search the web to find a solution but . :-
> > (
>
> > Here is my code:
>
> > models.py for Customer (in clients application)
> > -
> > class Customer (models.Model):
>
> >    email_adresse = models.EmailField(max_length=255, unique=True)
> >    some fields . for Step2 to Step4 of the form
> >    category = models.ManyToManyField(Categories)
> > -
>
> > models.py for categories (in categories application)
> > -
> > class Categories (models.Model):
> >    category = models.CharField(max_length=200)
>
> >    def __unicode__(self):
> >        return unicode(self.category)
> > -
>
> > The ManyToMany field has created(syncdb) a table
> > clients_customer_category with the following columns:
> >        1       id                      int(11)
> > AUTO_INCREMENT
> >        2       customer_id     int(11)
> >        3       categories_id   int(11)
>
> > urls.py
&g

Re: Formwizard - Many2Many field - instance needs to have a primary key value before a many-to-many relationship can be used

2011-11-02 Thread youpsla
Hi Furbeenator,
thanks a lots, it works !!! :-)))

I've use your first solution. You say that "category would have to be
the first Allow Null field in your model" wich is not the case here. A
"phone" field is the first step (Step0) can be empty :
telephone = models.CharField(max_length=14, blank=True)

Maybe I do a confusion between "Allow Null" and "blank=True) ?


To be sure to understand your solution, I go bellow step by step:

1 class InscriptionWizard(SessionWizardView):
2    def done(self, form_list, **kwargs):
3        instance = Customer()
4        for form in form_list:
5            for field, value in form.cleaned_data.iteritems():
6                if field == 'category':
7                    instance.save()
8                setattr(instance, field, value)
9        instance.save()

Line 5 : Iterate over field and values
Line 6 : If field name is category, then save the instance BEFORE
setting attribute (setattr) for the category field. Then a PK is
available in the DB for saving the m2m field category, wich is done
Line 9.

Is it the way it works and has to works ?


Again, thanks a lots for help  Yahoo !!!

Regards

Alain







On 2 nov, 19:03, Furbee <furbeena...@gmail.com> wrote:
> In your Customer model there are fields which cannot be Null, so you cannot
> instance.save() before setting those properties. So, you may have to check
> for the category field in your loop and if it is category, save the
> instance first. Something like the following:
>
> views.py (in clients application)
> -
> class InscriptionWizard(SessionWizardView):
>    def done(self, form_list, **kwargs):
>        instance = Customer()
>        for form in form_list:
>            for field, value in form.cleaned_data.iteritems():
>                if field == 'category':
>                    instance.save()
>                setattr(instance, field, value)
>        instance.save()
> -
>
> This would of course depend on your ordering of the fields. In other words,
> category would have to be the first Allow Null field in your model, because
> you cannot save() until all Not Null fields have a value. If you cannot
> order these fields so the category is last, you may have to do something
> like:
>
> views.py (in clients application)
> -
> class InscriptionWizard(SessionWizardView):
>    def done(self, form_list, **kwargs):
>        instance = Customer()
>        for form in form_list:
>            for field, value in form.cleaned_data.iteritems():
>                if field != 'category':
>                    setattr(instance, field, value)
>        instance.save()
>        for form in form_list:
>            for field, value in form.cleaned_data.iteritems():
>                if field == 'category':
>                    setattr(instance, field, value)
> -
>
> I'm sure there is a MUCH more elegant way of getting just the categories
> from the forms and field/value pairs, this is brute force (not very
> scalable for large number of fields), but should work. Anybody else please,
> show code that could get the specific forms and field/values for categories.
>
> Furbeenator
>
>
>
>
>
>
>
> On Wed, Nov 2, 2011 at 10:28 AM, youpsla <youp...@gmail.com> wrote:
> > Hello,
> > i'm currently doning a website where user can register (without
> > password, without auth module of Django). They put some informations
> > and at the end (Step5Form) do multiple choices by clicking on
> > checkboxes. When I click on validate on the last step I've "instance
> > needs to have a primary key value before a many-to-many relationship
> > can be used" error. I've search the web to find a solution but . :-
> > (
>
> > Here is my code:
>
> > models.py for Customer (in clients application)
> > -
> > class Customer (models.Model):
>
> >    email_adresse = models.EmailField(max_length=255, unique=True)
> >    some fields . for Step2 to Step4 of the form
> >    category = models.ManyToManyField(Categories)
> > -
>
> > models.py for categories (in categories application)
> > -
> > class Categories (models.Model):
> >    category = models.CharField(max_length=200)
>
> >    def __unicode__(self):
> >        return unicode(self.category)
> > -
>
> > The ManyToMany field has created(syncdb) a table
> > clients_custom

Formwizard - Many2Many field - instance needs to have a primary key value before a many-to-many relationship can be used

2011-11-02 Thread youpsla
Hello,
i'm currently doning a website where user can register (without
password, without auth module of Django). They put some informations
and at the end (Step5Form) do multiple choices by clicking on
checkboxes. When I click on validate on the last step I've "instance
needs to have a primary key value before a many-to-many relationship
can be used" error. I've search the web to find a solution but . :-
(

Here is my code:

models.py for Customer (in clients application)
-
class Customer (models.Model):

email_adresse = models.EmailField(max_length=255, unique=True)
some fields . for Step2 to Step4 of the form
category = models.ManyToManyField(Categories)
-

models.py for categories (in categories application)
-
class Categories (models.Model):
category = models.CharField(max_length=200)

def __unicode__(self):
return unicode(self.category)
-

The ManyToMany field has created(syncdb) a table
clients_customer_category with the following columns:
1   id  int(11) 
AUTO_INCREMENT
2   customer_id int(11)
3   categories_id   int(11)


urls.py
-
urlpatterns = patterns('',
(r'^clients/$', InscriptionWizard.as_view([Step1Form, Step2Form,
Step3Form, Step4Form, Step5Form])),
)
-


forms.py (in clients application)
-
from django import forms
from clients.models import Customer
from categories.models import Categories

class Step1Form(forms.Form):
email_adresse = forms.EmailField(max_length=255)

class Step5Form(forms.Form):
category =
forms.ModelMultipleChoiceField(queryset=Categories.objects.all(),
widget=forms.CheckboxSelectMultiple, required=True)


views.py (in clients application)
-
class InscriptionWizard(SessionWizardView):
def done(self, form_list, **kwargs):
instance = Customer()
for form in form_list:
for field, value in form.cleaned_data.iteritems():
setattr(instance, field, value)
instance.save()
-

I got the following error:
-
Request Method: POST
Request URL:http://127.0.0.1:8010/clients/
Django Version: 1.3.1
Exception Type: ValueError
Exception Value:
'Customer' instance needs to have a primary key value before a many-to-
many relationship can be used.
...
...
▶ Local vars
C:\dev\Flash\clients\views.py in done
setattr(instance, field, value) ...
-


What I've tried:
1)I've search the web and didn't find any way to solve this. I've read
on save_m2m() wich doesn't apply here as far I understand because no
"commit=False" and this form is not a ModelForm.


2)I've trie to save in 2 steps with the hope an id has been set in the
DB:
-First step : for form in form_list[0:3]: .. instance.save()
-Second step :
for form in form_list[4]:
for field, value in form.cleaned_data.iteritems():
instance.category.add(value)

I've the following error : 'BoundField' object has no attribute
'cleaned_data' for the line "for field, value in
form.cleaned_data.iteritems():" in Second step.


Then I can maybe split my form in 2 forms, one from Step0 to Step3 and
another one for Step4 and passing the id_customer in teh session but
maybe there is a solution to solve this issue in one form.


Help will be really appreciated.

I apologize if my explanations are not enough clear (and for my
english) and feel free to ask informations.

Regards

Alain




-- 
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 - Validation with a database lookup

2011-10-25 Thread youpsla
Hello,
I've done it !!! yooohooo.

But I think this is not the best way because it can be processor time
consuming if I've a lots of suscribers (Wich is not the case now).

Here is the code in forms.py:

class Step1Form(forms.Form):
email_adresse = forms.EmailField(max_length=255)
telephone = forms.CharField(max_length=14)

def clean(self):
"""
   Test if email_adresse is already in the database

"""

if 'email_adresse' in self.cleaned_data :
l = []
for p in Customer.objects.all():
l.append(p.email_adresse)
if self.cleaned_data['email_adresse'] in l:
raise forms.ValidationError(u'Email already exist')
return self.cleaned_data

It works 


I'll try with another method function:

p=Customer.objects.all()
try:
p.objects.filter(Customer__email_adresse__exact=
self.cleaned_data['email_adresse']
raise forms.ValidationError(u'Cette adresse Email est deja
utilisee')
return self.cleaned_data
except:
pass


If you have beter idea.

regards

Alain
Entry.objects.filter(blog__name__exact='Beatles Blog')


On 25 oct, 21:01, youpsla <youp...@gmail.com> wrote:
> Hello,
>
> I've setup a 5 steps form (There is only one table in the database).
> In the first step I ask for Email adresse. I ike this to be unique in
> the database.
>
> By putting parameters "unique=True" in models, the error only raise
> when submitting the form at the last step.
>
> Is there a way to do the lookup in the database when going from step 0
> (the one with Email field) to step 1. If Email adress already exist in
> the database, I like the step 0 form to be refreshed. Instead, go to
> step 1.
>
> Can somebody give me a way of doing this ?
>
> Regards
>
> Alain

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



Formwizard - Validation with a database lookup

2011-10-25 Thread youpsla
Hello,

I've setup a 5 steps form (There is only one table in the database).
In the first step I ask for Email adresse. I ike this to be unique in
the database.

By putting parameters "unique=True" in models, the error only raise
when submitting the form at the last step.

Is there a way to do the lookup in the database when going from step 0
(the one with Email field) to step 1. If Email adress already exist in
the database, I like the step 0 form to be refreshed. Instead, go to
step 1.

Can somebody give me a way of doing this ?


Regards

Alain

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



ModelForm - formwizard - Form on multiple pages

2011-10-22 Thread youpsla
Hello,
I'm buiding a website where users hae t fill a form. It's not a really
big one but I like to split it on multiple pages.

I can build the database with only one big table but I prefer for
update (index) reason split in 3 or 4 tables.

(Maybe you'll find some quetions like beginners one ... it's normal,
I'm a beginner).

Here is an extract of my models.py:
-
class Customer (models.Model):
email = models.EmailField(max_length=255, unique=True)
date_inscription = models.DateTimeField(auto_now_add=True)
date_modification = models.DateTimeField(auto_now=True)
telephone = models.CharField(max_length=14, blank=True)

class CustomerForm(ModelForm):
class Meta:
model = Customer

class CoordonneeDomicile (models.Model):
customer = models.ForeignKey('Customer')
adresse = models.CharField(max_length=255, blank=True)
cp = models.CharField(max_length=5)
ville = models.CharField(max_length=255)
pays = models.CharField(max_length=128, default='France')

class CoordonneeDomicileForm(ModelForm):
class Meta:
model = CoordonneeDomicile
-

urls.py:
-
from clients.models import CustomerForm, CoordonneeDomicileForm
from clients.views import InscriptionWizard

(r'^clients/$', InscriptionWizard.as_view([CustomerForm,
CoordonneeDomicileForm])),
-

views.py
-
class InscriptionWizard(SessionWizardView):
def done(self, form_list, **kwargs):
return render_to_response('done.html', {
'form_data': [form.cleaned_data for form in form_list],
})
-

FIrst, I'm not sure of the "customer = models.ForeignKey('Customer')"
in the "CoordonneeDomicile" class. I just want this field to be the
link between the two tables. I don't want a drop down menu be
generated by the formwizard in the step 2.

Is this one the good way to do things or maybe do I have to put all
datas in one table and use partial forms for each step ?

Maybe is there another way of doing things.

All comments are welcome.

Regards

Alain

-- 
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: Django 1.3.1 - Form on multiple pages

2011-10-21 Thread youpsla
Thanks a lots. I haven't take care of that before and I thought it has
been a source of confusion 

Thanks again

Alain

On 22 oct, 01:47, Kurtis Mullins <kurtis.mull...@gmail.com> wrote:
> Yep, you've got it. That stuff will be available in future releases. But if
> you want the 1.3 documents, just make sure you change that "dev" in the URL
> to "1.3". Don't worry, it happens a lot more often that you might think!
>
>
>
>
>
>
>
> On Fri, Oct 21, 2011 at 7:44 PM, youpsla <youp...@gmail.com> wrote:
> > Hi again,
> > in this link:
> >https://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/
>
> > the "/dev/" means that I'm reading the development docs ?
>
> > Regards
>
> > Alain
>
> > On 22 oct, 01:22, Kurtis Mullins <kurtis.mull...@gmail.com> wrote:
> > > No problem :) Also, make sure you're not reading the Development docs.
> > It's
> > > a different class all together in there.
>
> > > On Fri, Oct 21, 2011 at 7:02 PM, youpsla <youp...@gmail.com> wrote:
> > > > Sorry, I think I was wrong. I try to use SessionWizardView wich
> > > > require ton install the "django-formwizard" package from
> > > > djangopackages.
>
> > > > I think it will work now
>
> > > > Thanks
>
> > > > Alain
>
> > > > On 22 oct, 00:27, Kurtis Mullins <kurtis.mull...@gmail.com> wrote:
>
> >https://docs.djangoproject.com/en/1.3/ref/contrib/formtools/form-wizard/
>
> > > > > I don't believe it's deprecated in 1.3.1 but I could be wrong...
>
> > > > > On Fri, Oct 21, 2011 at 6:04 PM, youpsla <youp...@gmail.com> wrote:
> > > > > > Hello,
> > > > > > I like to know wich is the best splution to manage one form on
> > > > > > multiple pages with Gjango 1.3.1.
>
> > > > > > I've seen in the doc that there is a FormWizard Session or Cookies)
> > > > > > wich seems to be deprecated.
>
> > > > > > Then, is there a new mechanics for the 1.3.1 version ?
>
> > > > > > Thanks for your answers.
>
> > > > > > Regards
>
> > > > > > Alain
>
> > > > > > --
> > > > > > 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.

-- 
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: Django 1.3.1 - Form on multiple pages

2011-10-21 Thread youpsla
Hi again,
in this link:
https://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/

the "/dev/" means that I'm reading the development docs ?

Regards

Alain

On 22 oct, 01:22, Kurtis Mullins <kurtis.mull...@gmail.com> wrote:
> No problem :) Also, make sure you're not reading the Development docs. It's
> a different class all together in there.
>
>
>
>
>
>
>
> On Fri, Oct 21, 2011 at 7:02 PM, youpsla <youp...@gmail.com> wrote:
> > Sorry, I think I was wrong. I try to use SessionWizardView wich
> > require ton install the "django-formwizard" package from
> > djangopackages.
>
> > I think it will work now
>
> > Thanks
>
> > Alain
>
> > On 22 oct, 00:27, Kurtis Mullins <kurtis.mull...@gmail.com> wrote:
> > >https://docs.djangoproject.com/en/1.3/ref/contrib/formtools/form-wizard/
>
> > > I don't believe it's deprecated in 1.3.1 but I could be wrong...
>
> > > On Fri, Oct 21, 2011 at 6:04 PM, youpsla <youp...@gmail.com> wrote:
> > > > Hello,
> > > > I like to know wich is the best splution to manage one form on
> > > > multiple pages with Gjango 1.3.1.
>
> > > > I've seen in the doc that there is a FormWizard Session or Cookies)
> > > > wich seems to be deprecated.
>
> > > > Then, is there a new mechanics for the 1.3.1 version ?
>
> > > > Thanks for your answers.
>
> > > > Regards
>
> > > > Alain
>
> > > > --
> > > > 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: Django 1.3.1 - Form on multiple pages

2011-10-21 Thread youpsla
Sorry, I think I was wrong. I try to use SessionWizardView wich
require ton install the "django-formwizard" package from
djangopackages.

I think it will work now

Thanks

Alain



On 22 oct, 00:27, Kurtis Mullins <kurtis.mull...@gmail.com> wrote:
> https://docs.djangoproject.com/en/1.3/ref/contrib/formtools/form-wizard/
>
> I don't believe it's deprecated in 1.3.1 but I could be wrong...
>
>
>
>
>
>
>
> On Fri, Oct 21, 2011 at 6:04 PM, youpsla <youp...@gmail.com> wrote:
> > Hello,
> > I like to know wich is the best splution to manage one form on
> > multiple pages with Gjango 1.3.1.
>
> > I've seen in the doc that there is a FormWizard Session or Cookies)
> > wich seems to be deprecated.
>
> > Then, is there a new mechanics for the 1.3.1 version ?
>
> > Thanks for your answers.
>
> > Regards
>
> > Alain
>
> > --
> > 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.



Django 1.3.1 - Form on multiple pages

2011-10-21 Thread youpsla
Hello,
I like to know wich is the best splution to manage one form on
multiple pages with Gjango 1.3.1.

I've seen in the doc that there is a FormWizard Session or Cookies)
wich seems to be deprecated.

Then, is there a new mechanics for the 1.3.1 version ?

Thanks for your answers.

Regards

Alain

-- 
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: models.Model

2011-10-17 Thread youpsla
Hello Daniel
thanks for your answer and sorry for my english. As you said, it could be a 
problem of translation !!! :-)

I really appreciate your help, I'm doing lots of progress in my python 
object programming curve ...

OK, then to be sure how Python works ... let see this code:

1 from django.db import models 
2 
3 class Person(models.Model): 
4 first_name = models.CharField(max_length=30) 
5 last_name = models.CharField(max_length=30) 

Ligne 1 imports module "models". I've browse the source code of Django. In 
the "models" folder, there is a __init__.py file and a lots of .py other 
files.
There is folders too and specially one called "fields".

Here is my question :

   - When importing models on line 1, doest it import all the .py files in 
   this module, then  all classes, Class, functions, variables at the top level 
   of each .py are available for use ? Or there is only an automatic import of 
   the __init__.py ?


Line 4 : : The CharField Class definition is in models/fields/__init__.py. 
In the code above, there nowhere a reference at "fields". But the line 10 of 
the the __init__.py in models is " This file is automatically loaded by 
Python. In this file on line 10, there is "from django.db.models.fields 
import *". "

Here is my question :

   - Does it means that the CharField Class is available inside Person Class 
   because there is a cascading import following this way:
  - models contains an __init__.py wich import fields and __init.py in 
  fields has a definition of Class CharField on line 601
   
Hope it's enugh clear ... don't spend much time when it is not and just ask 
for reformulation, I'll dot it ...
Regards

Alain


-- 
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/-/WBCgsHwa0e0J.
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: models.Model

2011-10-17 Thread youpsla
hello again, sorry for eventually annoying. But later in the Django
tutorial,

there is this code:

from django.conf.urls import patterns, include, url
.
urlpatterns = patterns('',
(r'^polls/$', 'polls.views.index'),
..)),
)

What I understand here is that "patterns", "include" and "url" modules
are imported.

After the result of the function "patterns" is assigned to
"urlpatterns". AS Daniel said that a function can't be imported, this
means that a method can be called (but not imported) or this means
that a function and a method are not the same thing ?

Regards

Alain

On 17 oct, 08:53, Webb Newbie <new...@avatarific.com> wrote:
> "models" is a module that contains classes Model and CharField.
>
> Person inherits from Model.
>
> first_name and last_name are instances of CharField.
>
> There's no functional programming here.
>
> -WN.
>
>
>
>
>
>
>
> On Sun, Oct 16, 2011 at 6:43 PM, youpsla <youp...@gmail.com> wrote:
> > 1 from django.db import models
> > 2
> > 3 class Person(models.Model):
> > 4     first_name = models.CharField(max_length=30)
> > 5     last_name = models.CharField(max_length=30)

-- 
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: models.Model

2011-10-17 Thread youpsla
Thanks you 2 for your answers.

I think I've understood now. Again I apologize for the newby Python
question but I've read three times "Dive in Python" and it hasn't made
me thnigs clear. That's the reason why I've posted.

I thought there was a hierarchy like this models.Model.CharField 

That's the reason why I didn't understood.

Daniel, you said, that a method can be imported, this mean that an
external method (method from a class like Model) can't be used
directly in the Person class for example ?

If I understand well, in "first_name =
models.CharField(max_length=30)", first_name is an instance of class
CharField. This instance send "30" to the "max_length" parameter of
class CharField. This parameter is used by an internal method of class
CharFiled. Is that right ? :-)

Thanks again to all

Regards

Alain



On 17 oct, 08:53, Webb Newbie <new...@avatarific.com> wrote:
> "models" is a module that contains classes Model and CharField.
>
> Person inherits from Model.
>
> first_name and last_name are instances of CharField.
>
> There's no functional programming here.
>
> -WN.
>
>
>
>
>
>
>
> On Sun, Oct 16, 2011 at 6:43 PM, youpsla <youp...@gmail.com> wrote:
> > 1 from django.db import models
> > 2
> > 3 class Person(models.Model):
> > 4     first_name = models.CharField(max_length=30)
> > 5     last_name = models.CharField(max_length=30)

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



models.Model

2011-10-16 Thread youpsla
Hello,
I'm new to Django and I've only a medium background in funtionnal
programming in Python.

I'm currently reading and working on the Django tutorial. I've few
questions on a example of code because things are not so clear for me.

Here is the code example

1 from django.db import models
2
3 class Person(models.Model):
4 first_name = models.CharField(max_length=30)
5 last_name = models.CharField(max_length=30)

Can you say me if I'm wrong or not on the followings:

- line 1 : Import of the" models" method from the "django.db"
module ?

- line 3 : Définition of the "Person" classs wich heritates from the
"models.Model class ? If true, and assuming that "models" is a method,
a class can be nested in a method ?

- ligne 4 : Creation of variable "first_name" by calling the method
CharField with one argument. But how "CharFiled" is written, isn't it
a class ? ANd here we use only "models", then why on line 3 we use
"models.Model" ?

I hope it's not to much confusing  :-)

Help would be REALLY appreciated !!!

Regards

Alain

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