Re: Object composition in django

2013-02-13 Thread Jani Tiainen

Hi,

You're trying to setup one-to-one relationship.

It means that producer.mailing_address does have exactly one unique 
Address entity. Same goes for physical_address.


What you want is really ForeignKey to address which means that you reuse 
addresses to multiple producer.mailing_address.


Then you can omit related names, or like someone suggested use different 
related names for both fields.


13.2.2013 21:25, Ray Hatfield kirjoitti:

Hi,

I have a model which requires two addresses: a mailing address and a
physical address. From an OO perspective it makes sense to have an
Address class and the Producer to have Address instances as properties,
but I can't seem to achieve this in django while still being able to
edit the addresses inline as part of the Producer admin.

I've tried this sort of thing:

class Address( models.Model ):
 street = models.CharField( ... )
 # city state zip, etc.

class Producer( models.Model ):
 mailing_address = models.OneToOneField( Address, related_name='+' )
 physical_address = models.OneToOneField( Address, related_name='+' )

but when I attempt to inline the addresses in the django admin I run
into trouble. I get errors like:

 has no ForeignKey to 

(This error is true, of course. But I was under the apparently erroneous
impression that including related_name='+' would prevent django from
setting up the reverse relationship.)

I realize I could add a foreign key to Address to associate it with a
specific Producer but this feels backwards to me. An Address shouldn't
need to know whether it's for a Producer or some other object. It's just
an address.

I've been banging my head on this for far too long. Advice?

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.





--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django generate pdf with tables and charts

2013-02-13 Thread Ovnicraft
On Sun, Feb 10, 2013 at 11:10 AM, Jaimin Patel  wrote:

> I am trying to generate pdf using django template, also need some support
> of javascript code. I have tried PISA, ReportLib and wkhtmltopdf but it
> seems that it doesn't wait for Javascript.


Hello, can you explain us better what you means with *does not wait for JS*
?
I understand you say: pdf is rendered w/o running JS code.

Regards,

>
> Can someone suggest good solution or example?
>
> --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Cristian Salamea
@ovnicraft

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django generate pdf with tables and charts

2013-02-13 Thread Waitman Gobble
On Feb 10, 2013 8:11 AM, "Jaimin Patel"  wrote:
>
> I am trying to generate pdf using django template, also need some support
of javascript code. I have tried PISA, ReportLib and wkhtmltopdf but it
seems that it doesn't wait for Javascript.
>
> Can someone suggest good solution or example?
>
> --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

You could send a request using Ajax, to a cgi program on the server, and
include the URL. The program would pull the content and convert to pdf,
then return the URL of the document. If the user has to be authenticated to
view the content, then you would have to pass the authentication key to the
CGI program. You may find something like html2pdf will do the conversion,
there are free and non-free programs available.

Waitman Gobble
San Jose California USA

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django generate pdf with tables and charts

2013-02-13 Thread Peter of the Norse
Django doesn’t run Javascript, that’s done in the browser. If you really want 
to have JS processing you’ll have to open a web browser and then print to PDF.

On Feb 10, 2013, at 9:10 AM, Jaimin Patel wrote:

> I am trying to generate pdf using django template, also need some support of 
> javascript code. I have tried PISA, ReportLib and wkhtmltopdf but it seems 
> that it doesn't wait for Javascript. 
> 
> Can someone suggest good solution or example?
> 

Peter of the Norse
rahmc...@radio1190.org



-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django 1.5 AbstractBaseUser with char primary key not JSON serializable

2013-02-13 Thread Russell Keith-Magee
On Wed, Feb 13, 2013 at 9:51 PM, Kaloian  wrote:

>
> Hi Russell,
>
>
> Thanks for the responce! I actually found the problem it was not where I
> was looking for it and it was more of a typo.
> And your suggestion No.2 appears to be right:
>
> * Do you have any models with foreign keys to your custom user? (i.e., is
>> the problem manifesting when serialising Merchant, or serialising foreign
>> keys to Merchant?)
>>
>
> I am having a Product model with foreignkey to the Merchant model which
> had natural key method defined as follows:
>
> class Product(models.Model):
> name = models.CharField(max_length=200)
> #merchant = models.ForeignKey(Merchant, to_field='api_key')
> merchant = models.ForeignKey(Merchant)
> url = models.URLField(max_length = 2000)
> description = models.TextField(blank=True)
> client_product_id = models.CharField(max_length='100')
>
> objects = ProductManager()
> class Meta:
> verbose_name = 'Product'
> verbose_name_plural = 'Products'
> unique_together = ('merchant', 'client_product_id',)
>
> def __unicode__(self):
> return self.name
>
> def natural_key(self):
> return (self.merchant, self.client_product_id)
>
> The natural_key method returned self.merchant instead of self.merchant_id
> so it was trying to serialize the whole merchant object to make a natural
> key.  After switching this to merchant_id it is working properly.


Glad you found the problem (and even more glad it isn't something I need to
fix :-)


> As a side note -- if you're using email as your username field, you should
>> set it as unique=True -- USERNAME_FIELD needs to be unique or you'll
>> experience problems later on. This is something that should probably be
>> caught by validation - which is a bug deserving of it's own report. For
>> performance reasons, you also probably want to set it db_index=True, since
>> you're going to be searching on that field fairly often, so having an index
>> on it makes sense.
>>
>
> Thanks for the notes I will for sure add these, but shouldn't both(unique
> and db_index) be added by default when you set your USERNAME_FIELD .
>

That's an interesting suggestion; I suppose it comes down to a question of
"explicit vs implicit". If being named in USERNAME_FIELD magically made the
field unique and indexed, the developer needs to implicitly know that this
will happen. If a developer actually *wanted* the username field to be
non-unique, they might get a surprise when they find that it isn't. Of
course, this points at a design problem on their end; the difference is
that if it is implicit, they will discover the problem by accident when a
non-unique username is rejected; if it is raised as a validation error,
they'll get an error when they sync their tables (giving them an indication
that the problem must be fixed).

I've opened ticket #19822 to track this problem.

Yours,
Russ Magee %-)

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django 1.5 - release date

2013-02-13 Thread Russell Keith-Magee
Hi Martin,

We posted an update to the blog a couple of weeks ago [1]; we should be in
a position to release the second RC in the very near future.

[1]
https://www.djangoproject.com/weblog/2013/jan/24/delay-final-release-django-15/

I'm sorry I can't give any more concrete answer than that -- because Django
is a project run by volunteers, it's hard to know in advance what resources
will be available to perform the work that needs to be done.

Yours,
Russ Magee %-)

On Wed, Feb 13, 2013 at 6:53 PM, Martin B.  wrote:

> Hmm, the list of blockers seems to be empty. Seeing as its been a while
> since the last update here, any news on a rc/stable release?
>
> On Sunday, December 30, 2012 1:19:04 AM UTC, Russell Keith-Magee wrote:
>
>>
>> On Sat, Dec 29, 2012 at 2:44 PM, Aidan Zhakypov wrote:
>>
>>> Does anyone know when Django 1.5 is going to be released as a stable
>>> version? If I want to *start* developing a production web site, should
>>> I write it on Django 1.4 or is it already ok to implement it on Django 1.5?
>>
>>
>> It's difficult to give an exact date for the release of Django 1.5. We've
>> put out 2 beta releases, which means there are no more features to be
>> added; and the list of release blocking bugs is down to single figures [1].
>>
>> If I were to guess, I'd say we're less than a month from the final
>> release of 1.5. However, this is all dependent on how many new release
>> blocking bugs are discovered between now and then, and the resources that
>> the community and the core team can devote to getting the release out the
>> door.
>>
>> Whether that suits your own development schedule is up to you.
>>
>> The good news is that unless you're planning to use a new feature from
>> 1.5 (e.g., pluggable User models), it shouldn't really matter whether you
>> start developing using Django 1.4 or Django 1.5. Django has a strict
>> backwards compatibility policy, so the migration process from 1.4 to 1.5
>> should be very smooth.
>>
>> [1] https://code.**djangoproject.com/query?**status=assigned=new&*
>> *status=reopened=**Release+blocker
>>
>> Yours,
>> Russ Magee %-)
>>
>  --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Object composition in django

2013-02-13 Thread Ray Hatfield
I've considered the address-type-and-foreign-key approach you describe — 
and implemented it and then backed it out again — but that approach bugs me 
at a philosophical level. Address is then bound explicitly to Producer and 
instead of having two addresses each with a specific designation I can have 
0-n addresses, one producer with 14 physical addresses, and so on. I 
understand that I can guard against these situations through validation and 
overriding save methods and such but object composition seems like such a 
simple, common, basic need I'm stunned to find it's not easily achievable.

Thanks for the input.


On Wednesday, February 13, 2013 2:59:56 PM UTC-6, Adam Mesha wrote:
>
> Inlines are for related objects, meaning when I have a foreign key from A 
> to B, on A there is an actual database field that points to B, but on B 
> there's a virtual (related object) field implemented as a python method. 
> When you have a foreign key, the way the admin shows that is just to give 
> you a drop-down list so you can choose the corresponding object in the 
> other model.
>
> To go back to the standard example, there is a foreign key pointing from 
> Book to Author. On the Author admin page you can see and edit all the 
> books, but on the Book page you just have a drop-down to select the 
> relevant author. You could think of it as Book extends in a certain sense 
> Author, so it has a field pointing to its parent.
>
> What I would probably do in your situation is to get rid of the mailing 
> address and physical address in your Producer model, and add a type 
> field(which could be 'mailing' or 'physical' or maybe some more 
> possibilities) and a producer field foreign key. That would allow for 
> easily adding more types of addresses, and more than one of a given type. 
> If it's essential to guarantee that there is exactly one mailing address 
> and exactly one physical address, I would probably override the relevant 
> save methods to check for that when objects are saved.
>
> On Wed, Feb 13, 2013 at 9:25 PM, Ray Hatfield 
>  > wrote:
>
>> Hi,
>>
>> I have a model which requires two addresses: a mailing address and a 
>> physical address. From an OO perspective it makes sense to have an Address 
>> class and the Producer to have Address instances as properties, but I can't 
>> seem to achieve this in django while still being able to edit the addresses 
>> inline as part of the Producer admin.
>>
>> I've tried this sort of thing:
>>
>> class Address( models.Model ):
>> street = models.CharField( ... )
>> # city state zip, etc.
>>
>> class Producer( models.Model ):
>> mailing_address = models.OneToOneField( Address, related_name='+' )
>> physical_address = models.OneToOneField( Address, related_name='+' )
>>
>> but when I attempt to inline the addresses in the django admin I run into 
>> trouble. I get errors like:
>>
>>  has no ForeignKey to > 'producers.models.Producer'>
>>
>> (This error is true, of course. But I was under the apparently erroneous 
>> impression that including related_name='+' would prevent django from 
>> setting up the reverse relationship.)
>>
>> I realize I could add a foreign key to Address to associate it with a 
>> specific Producer but this feels backwards to me. An Address shouldn't need 
>> to know whether it's for a Producer or some other object. It's just an 
>> address.
>>
>> I've been banging my head on this for far too long. Advice?
>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>
>
> -- 
> Adam Mesha 
>  

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Question from a very beginner: Include dynamic template

2013-02-13 Thread Daniel Roseman
On Wednesday, 13 February 2013 03:52:20 UTC-8, Olivier wrote:

> But before including template ( tasklist-one.html ) I would like to call a 
> function  which take the tasklist_id and look for the task which compose 
> the tasklist.
>

Why? You don't show your models, which would have been useful, but 
presumably there's a ForeignKey from Task to Tasklist. So instead of 
passing the tasklist ID to the child template, just pass the actual 
tasklist object, then you can refer to the tasks via the reverse 
relationship: {{ tasklist.task_set.all }}

--
DR.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Object composition in django

2013-02-13 Thread Adam Mesha
Inlines are for related objects, meaning when I have a foreign key from A
to B, on A there is an actual database field that points to B, but on B
there's a virtual (related object) field implemented as a python method.
When you have a foreign key, the way the admin shows that is just to give
you a drop-down list so you can choose the corresponding object in the
other model.

To go back to the standard example, there is a foreign key pointing from
Book to Author. On the Author admin page you can see and edit all the
books, but on the Book page you just have a drop-down to select the
relevant author. You could think of it as Book extends in a certain sense
Author, so it has a field pointing to its parent.

What I would probably do in your situation is to get rid of the mailing
address and physical address in your Producer model, and add a type
field(which could be 'mailing' or 'physical' or maybe some more
possibilities) and a producer field foreign key. That would allow for
easily adding more types of addresses, and more than one of a given type.
If it's essential to guarantee that there is exactly one mailing address
and exactly one physical address, I would probably override the relevant
save methods to check for that when objects are saved.

On Wed, Feb 13, 2013 at 9:25 PM, Ray Hatfield wrote:

> Hi,
>
> I have a model which requires two addresses: a mailing address and a
> physical address. From an OO perspective it makes sense to have an Address
> class and the Producer to have Address instances as properties, but I can't
> seem to achieve this in django while still being able to edit the addresses
> inline as part of the Producer admin.
>
> I've tried this sort of thing:
>
> class Address( models.Model ):
> street = models.CharField( ... )
> # city state zip, etc.
>
> class Producer( models.Model ):
> mailing_address = models.OneToOneField( Address, related_name='+' )
> physical_address = models.OneToOneField( Address, related_name='+' )
>
> but when I attempt to inline the addresses in the django admin I run into
> trouble. I get errors like:
>
>  has no ForeignKey to  'producers.models.Producer'>
>
> (This error is true, of course. But I was under the apparently erroneous
> impression that including related_name='+' would prevent django from
> setting up the reverse relationship.)
>
> I realize I could add a foreign key to Address to associate it with a
> specific Producer but this feels backwards to me. An Address shouldn't need
> to know whether it's for a Producer or some other object. It's just an
> address.
>
> I've been banging my head on this for far too long. Advice?
>
> --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Adam Mesha 

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Object composition in django

2013-02-13 Thread Bill Freeman
You might try specifying distinct related names, just off the cuff.  -Bill

On Wed, Feb 13, 2013 at 2:25 PM, Ray Hatfield wrote:

> Hi,
>
> I have a model which requires two addresses: a mailing address and a
> physical address. From an OO perspective it makes sense to have an Address
> class and the Producer to have Address instances as properties, but I can't
> seem to achieve this in django while still being able to edit the addresses
> inline as part of the Producer admin.
>
> I've tried this sort of thing:
>
> class Address( models.Model ):
> street = models.CharField( ... )
> # city state zip, etc.
>
> class Producer( models.Model ):
> mailing_address = models.OneToOneField( Address, related_name='+' )
> physical_address = models.OneToOneField( Address, related_name='+' )
>
> but when I attempt to inline the addresses in the django admin I run into
> trouble. I get errors like:
>
>  has no ForeignKey to  'producers.models.Producer'>
>
> (This error is true, of course. But I was under the apparently erroneous
> impression that including related_name='+' would prevent django from
> setting up the reverse relationship.)
>
> I realize I could add a foreign key to Address to associate it with a
> specific Producer but this feels backwards to me. An Address shouldn't need
> to know whether it's for a Producer or some other object. It's just an
> address.
>
> I've been banging my head on this for far too long. Advice?
>
> --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Is there an easy way to popup forms?

2013-02-13 Thread jirka . vejrazka
Probably the easiest way is to use a JS/CSS framework that has a good support 
for popups and forms. There are a lot out there. I have personal experience 
with Bootstrap (one of the most popular these days) - check its documentation 
(look for both "popup" and "modal"), also search for available bootstrap 
plugins - plenty exist.

  If you wanted to stick with jQuery, check out jQuery UI - a set of reusable 
components that might suit your needs.

  HTH

Jirka

-Original Message-
From: frocco 
Sender: django-users@googlegroups.com
Date: Wed, 13 Feb 2013 11:35:36 
To: 
Reply-To: django-users@googlegroups.com
Cc: 
Subject: Re: Is there an easy way to popup forms?

Thanks Tom,

Do you know how I would have a form display using this?


On Wednesday, February 13, 2013 11:41:59 AM UTC-5, Tom Evans wrote:
>
> On Wed, Feb 13, 2013 at 4:12 PM, frocco  
> wrote: 
> > I have a form I want to popup and am having trouble getting this to 
> work. 
> > This is not in the admin page. 
> > 
> > Can someone give me an example? 
> > 
> > Thanks 
> > 
>
> An easy way to do a pop up form is to use a jqueryui dialog¹ 
>
> http://api.jqueryui.com/dialog/ 
>
> Cheers 
>
> Tom 
>
> ¹ Other dialogs are available, consult your local google 
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Is there an easy way to popup forms?

2013-02-13 Thread frocco
Thanks Tom,

Do you know how I would have a form display using this?


On Wednesday, February 13, 2013 11:41:59 AM UTC-5, Tom Evans wrote:
>
> On Wed, Feb 13, 2013 at 4:12 PM, frocco  
> wrote: 
> > I have a form I want to popup and am having trouble getting this to 
> work. 
> > This is not in the admin page. 
> > 
> > Can someone give me an example? 
> > 
> > Thanks 
> > 
>
> An easy way to do a pop up form is to use a jqueryui dialog¹ 
>
> http://api.jqueryui.com/dialog/ 
>
> Cheers 
>
> Tom 
>
> ¹ Other dialogs are available, consult your local google 
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Object composition in django

2013-02-13 Thread Ray Hatfield
Hi,

I have a model which requires two addresses: a mailing address and a 
physical address. From an OO perspective it makes sense to have an Address 
class and the Producer to have Address instances as properties, but I can't 
seem to achieve this in django while still being able to edit the addresses 
inline as part of the Producer admin.

I've tried this sort of thing:

class Address( models.Model ):
street = models.CharField( ... )
# city state zip, etc.

class Producer( models.Model ):
mailing_address = models.OneToOneField( Address, related_name='+' )
physical_address = models.OneToOneField( Address, related_name='+' )

but when I attempt to inline the addresses in the django admin I run into 
trouble. I get errors like:

 has no ForeignKey to 

(This error is true, of course. But I was under the apparently erroneous 
impression that including related_name='+' would prevent django from 
setting up the reverse relationship.)

I realize I could add a foreign key to Address to associate it with a 
specific Producer but this feels backwards to me. An Address shouldn't need 
to know whether it's for a Producer or some other object. It's just an 
address.

I've been banging my head on this for far too long. Advice?

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Django FormWizards: How to painlessly pass user-entered data between forms?

2013-02-13 Thread Saqib Ali


Crossposting from 
here: 
http://stackoverflow.com/questions/14860392/django-formwizards-how-to-painlessly-pass-user-entered-data-between-forms

I'm using the FormWizard functionality in Django 1.4.3.

I have successfully created a 4-step form. In the first 3 steps of the form 
it correctly takes information from the user, validates it, etc. In Step 
#4, it right now just shows a "Confirm" button. Nothing else. When you hit 
"Confirm" on step #4, does something useful with it in the done() function. 
So far it all works fine.

However, I would like to make it so that in step 4 (The confirmation step), 
it shows the user the data they have entered in the previous steps for 
their review. I'm trying to figure out the most painless way to make this 
happen. So far I am creating an entry in the context called formList which 
contains a list of forms that have already been completed.

class my4StepWizard(SessionWizardView):

def get_template_names(self):
return [myWizardTemplates[self.steps.current]]

def get_context_data(self, form, **kwargs):
context = super(my4StepWizard, self).get_context_data(form=form, 
**kwargs)
formList = [self.get_form_list()[i[0]] for i in 
myWizardForms[:self.steps.step0]]

context.update(
{
'formList': formList,
}
)
return context


def done(self, form_list, **kwargs):
# Do something here.
return HttpResponseRedirect('/doneWizard')

Form #1 has an input field called myField. So in my template for step #4, I 
would like to do {{ formList.1.clean_myField }}. However, when I do that, I 
get the following error:

*Exception Value:
'my4StepWizard' object has no attribute 'cleaned_data'*

It seems that the forms I am putting into formList are unbounded. So they 
don't contain the user's data. Is there a fix I can use to get the data 
itself? I would really like to use the context to pass the data as I'm 
doing above.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django environment setup path problem

2013-02-13 Thread Bill Freeman
This is a version 1.4 Django.  Yes?

Try adding to manage.py, between the "if ..." line and the "os.environ..."
lines, and indented like the "os.environ..." line:

import pdb;pdb.set_trace()

Then run:

   $ ./manage.py shell

When it stops at the breakpoint, type:

  p os.environ['DJANGO_SETTINGS_MODULE']

I expect this to complain that there is no such key.  Now type:

  n

to single step over the setdefault line and again type:

  p os.environ['DJANGO_SETTINGS_MODULE']

This time it should be happy and print something like:

  "firstdjango.settings"

Now try typeing (be sure to include the "!"):

  !import firstdjango.settings as s

and if that doesn't raise an error, try:

  pp s.INSTALLED_APPS

If this stuff isn't working do:

  p os.getcwd()
  pp sys.path

Assuming that the current working directory is the one containing manage.py
and the like named directory that in turn contains settings.py, then either
it must be on sys.path, or an empty string (more likely) will be on
sys.path (implying the use of the current working directory).

If everything so far was good, and nobody has a better suggestion, and you
want to take the time, then you can use the "m" command again to step over
the "from ... import ..." line, and then the "s" command to step into the
"execute_from_command_line" function, use "n" to step through it's parts
until you find the one that fails, exit, restart, step back to the failing
part and step into it, repeat until enlightened.

Bill


On Wed, Feb 13, 2013 at 9:20 AM, Yussi  wrote:

> I see what you're doing, (It did take me half an hour of staring at your
> email though)
>
> The steps are:
> $django-admin startproject myproj
> $cd myproj
> $vi myproj/settings.py
> than add your databases
> than run
> $./manage.py syncdb
> not django-admin syncdb
>
>
> On 13/02/13 13:54, Bill Freeman wrote:
>
>> How are you invoking manage.py?  Try cd'ing to the directory containing
>> it before running it and see if that helps.  (That directory will then
>> automatically be on python's sys.path, which is needed.
>> DJANGO_SETTINGS_MODULE must be a python style package.module style path,
>> not a filesystem path, so depending on what yout mean by "path to
>> project" I wouldn't expect your second approach to work either.)
>>
>> On Wed, Feb 13, 2013 at 1:57 AM, kulbhushan patariya
>> > >>
>> wrote:
>>
>> Hi,
>> I have following problem regarding Django.
>> Can anyone help me out
>> --**__**
>> --__-
>> kbjp@kbjp-VGN-CS35GN-B:~/__**Desktop/kbproject/firstjango$
>>
>> django-admin.py syncdb
>> Traceback (most recent call last):
>>File "/usr/local/bin/django-admin._**_py", line 5, in 
>>  management.execute_from___**command_line()
>>File
>> "/usr/local/lib/python2.7/__**dist-packages/django/core/__**
>> management/__init__.py",
>>
>> line 443, in execute_from_command_line
>>  utility.execute()
>>File
>> "/usr/local/lib/python2.7/__**dist-packages/django/core/__**
>> management/__init__.py",
>> line 382, in execute
>>  self.fetch_command(subcommand)**__.run_from_argv(self.argv)
>>File
>> "/usr/local/lib/python2.7/__**dist-packages/django/core/__**
>> management/__init__.py",
>>
>> line 261, in fetch_command
>>  klass = load_command_class(app_name, subcommand)
>>File
>> "/usr/local/lib/python2.7/__**dist-packages/django/core/__**
>> management/__init__.py",
>> line 69, in load_command_class
>>  module = import_module('%s.management._**_commands.%s' %
>> (app_name, name))
>>File
>> "/usr/local/lib/python2.7/__**dist-packages/django/utils/__**
>> importlib.py",
>>
>> line 35, in import_module
>>  __import__(name)
>>File
>> "/usr/local/lib/python2.7/__**dist-packages/django/core/__**
>> management/commands/syncdb.py"**__,
>>
>> line 8, in 
>>  from django.core.management.sql import custom_sql_for_model,
>> emit_post_sync_signal
>>File
>> "/usr/local/lib/python2.7/__**dist-packages/django/core/__**
>> management/sql.py",
>>
>> line 6, in 
>>  from django.db import models
>>File
>> "/usr/local/lib/python2.7/__**dist-packages/django/db/**
>> init__.py",
>>
>> line 11, in 
>>  if DEFAULT_DB_ALIAS not in settings.DATABASES:
>>File
>> "/usr/local/lib/python2.7/__**dist-packages/django/utils/__**
>> functional.py",
>>
>> line 184, in inner
>>  self._setup()
>>File
>> "/usr/local/lib/python2.7/__**dist-packages/django/conf/**init__.py",
>> line
>>
>> 40, in _setup
>>  raise ImportError("Settings cannot be imported, because
>> environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
>> ImportError: Settings cannot be 

Hierarchical data in admin pages in Django

2013-02-13 Thread Almudena Vila Forcén


In a Django project, I have a hierarchical model using MPTT defined like 
this in models.py:

class Structure(MPTTModel):
name = models.CharField(max_length=200, unique=True)
parent = TreeForeignKey('self', null=True, blank=True, 
related_name='children')
[...]

I'm using FeinCMS to show this hierarchical data in admin pages. I do it 
like this in admin.py:

class StructureAdmin(tree_editor.TreeEditor)
search_fields = ('name',)
[...]

admin.site.register(Structure, StructureAdmin)

 In the admin model page, it works perfectly and the hierarchy can be seen:

[image: enter image description here]

It also works when editing or adding:

[image: enter image description here]

I have another model in models.py:

class Track(models.Model):
initialStructure = models.ForeignKey(Structure , 
related_name='track_initialStructure')
finalStructure = models.ForeignKey(Structure, 
related_name='track_finalStructure')
[...]

However, when adding a new element of this kind, the hierarchy can not be 
seen:

[image: enter image description here]

I've tried to use tree_editor.TreeEditor for the admin view of Track but it 
gives a lot of errors because Track is not hierarchical, but some of its 
ForeignKey's are. How could I show the hierarchy when editing an element of 
model Track?

Thank you very much.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: def __unicode__(self) in models.py is not working

2013-02-13 Thread David
It appears as though when using Python3.3 and Django 1.6dev you should use 
__str__ and not __unicode__.  __unicode__ seems to be gone from Python3.3

On Tuesday, February 12, 2013 4:45:33 PM UTC-5, David wrote:
>
> I am working through the tutorial and find that the *def 
> __unicode__(self):* command to give an object a readable name in admin is 
> not working.  I am cutting code from the tutorial.  When I access the 
> detail screen in /admin/ all I see is [table name] object and not the name 
> I defined in def __unicode__(self): return: self.name
>
> I am working with the 1.6dev release in a 64bit Win7 environment.
>
> Is this a known issue with dev?  I have searched Django users without 
> success.
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Is there an easy way to popup forms?

2013-02-13 Thread Tom Evans
On Wed, Feb 13, 2013 at 4:12 PM, frocco  wrote:
> I have a form I want to popup and am having trouble getting this to work.
> This is not in the admin page.
>
> Can someone give me an example?
>
> Thanks
>

An easy way to do a pop up form is to use a jqueryui dialog¹

http://api.jqueryui.com/dialog/

Cheers

Tom

¹ Other dialogs are available, consult your local google

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Is there an easy way to popup forms?

2013-02-13 Thread frocco
I have a form I want to popup and am having trouble getting this to work.
This is not in the admin page.

Can someone give me an example?

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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Testing view's get_context_data(): why does MultipleObjectMixin.get_context_data() require "object_list" in kwargs?

2013-02-13 Thread benoit . bryon
Hi,

While writing tests for views, I discovered the following code and wondered 
whether it is a feature or a potentially bad pattern...

* BaseListView sets self.object_list: 
https://github.com/django/django/blob/ec469ade2b04b94bfeb59fb0fc7d9300470be615/django/views/generic/list.py#L137
* Then BaseListView passes object_list as keyword argument to 
get_context_data(): 
https://github.com/django/django/blob/ec469ade2b04b94bfeb59fb0fc7d9300470be615/django/views/generic/list.py#L152
* But the first thing MultipleObjectMixin.get_context_data() does is 
kwargs.pop('object_list'): 
https://github.com/django/django/blob/ec469ade2b04b94bfeb59fb0fc7d9300470be615/django/views/generic/list.py#L108
* Note: this implementation makes "object_list" argument mandatory for 
get_context_data.

Questions are:

* could MultipleObjectMixin.get_context_data() use self.object_list 
directly? i.e. avoid passing it as kwarg in BaseListView.
* looks like BaseListView.object_list could be some property(get_queryset), 
doesn't it?


Here are notes about the use-case that made me ask... **Am I asking the 
right questions?**

My use case is to write tests for class-based views. I'm testing 
get_context_data() of some custom ListView. Currently I have to pass it 
some arbitrary object_list argument, but I wish the "object_list" context 
data was computed automatically from get_queryset.
Here is a test I wish I could write:

.. code-block:: python::

   class MyModelListViewTestCase(TestCase):
   """Test non-standard behaviour of MyModelListView."""
   def test_context_data(self):
   """get_context_data() contains expected keys/values."""
   instance = MyModel.objects.create()
   request = self.request_factory()  # Uses 
django.test.RequestFactory
   view = self.view_factory(request)  # Populates request, args and 
kwargs attributes, just like dispatch() would.
   data = view.get_context_data(**view.kwargs)  # I also wish I 
could ``data = view.get_context_data()``
   self.assertEqual(data['object_list'], [instance])
   self.assertEqual(data['some_custom_context_var'], 'custom_value')
 
Notice that I use "view.get_context_data(**view.kwargs)" because 
[https://github.com/django/django/blob/ec469ade2b04b94bfeb59fb0fc7d9300470be615/django/views/generic/base.py#L153
 
that's what TemplateView does]... and I really don't understand why 
BaseListView passes "object_list".
In fact, I also wonder why get_context_data() is passed kwargs that are 
already made available as self.kwargs by dispatch...
But I guess I'm missing something ;) ... Any idea?

Regards,

Benoît

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django environment setup path problem

2013-02-13 Thread Yussi
I see what you're doing, (It did take me half an hour of staring at your 
email though)


The steps are:
$django-admin startproject myproj
$cd myproj
$vi myproj/settings.py
than add your databases
than run
$./manage.py syncdb
not django-admin syncdb

On 13/02/13 13:54, Bill Freeman wrote:

How are you invoking manage.py?  Try cd'ing to the directory containing
it before running it and see if that helps.  (That directory will then
automatically be on python's sys.path, which is needed.
DJANGO_SETTINGS_MODULE must be a python style package.module style path,
not a filesystem path, so depending on what yout mean by "path to
project" I wouldn't expect your second approach to work either.)

On Wed, Feb 13, 2013 at 1:57 AM, kulbhushan patariya
> wrote:

Hi,
I have following problem regarding Django.
Can anyone help me out

--__--__-
kbjp@kbjp-VGN-CS35GN-B:~/__Desktop/kbproject/firstjango$
django-admin.py syncdb
Traceback (most recent call last):
   File "/usr/local/bin/django-admin.__py", line 5, in 
 management.execute_from___command_line()
   File

"/usr/local/lib/python2.7/__dist-packages/django/core/__management/__init__.py",
line 443, in execute_from_command_line
 utility.execute()
   File

"/usr/local/lib/python2.7/__dist-packages/django/core/__management/__init__.py",
line 382, in execute
 self.fetch_command(subcommand)__.run_from_argv(self.argv)
   File

"/usr/local/lib/python2.7/__dist-packages/django/core/__management/__init__.py",
line 261, in fetch_command
 klass = load_command_class(app_name, subcommand)
   File

"/usr/local/lib/python2.7/__dist-packages/django/core/__management/__init__.py",
line 69, in load_command_class
 module = import_module('%s.management.__commands.%s' %
(app_name, name))
   File
"/usr/local/lib/python2.7/__dist-packages/django/utils/__importlib.py",
line 35, in import_module
 __import__(name)
   File

"/usr/local/lib/python2.7/__dist-packages/django/core/__management/commands/syncdb.py"__,
line 8, in 
 from django.core.management.sql import custom_sql_for_model,
emit_post_sync_signal
   File
"/usr/local/lib/python2.7/__dist-packages/django/core/__management/sql.py",
line 6, in 
 from django.db import models
   File
"/usr/local/lib/python2.7/__dist-packages/django/db/init__.py",
line 11, in 
 if DEFAULT_DB_ALIAS not in settings.DATABASES:
   File
"/usr/local/lib/python2.7/__dist-packages/django/utils/__functional.py",
line 184, in inner
 self._setup()
   File
"/usr/local/lib/python2.7/__dist-packages/django/conf/init__.py", line
40, in _setup
 raise ImportError("Settings cannot be imported, because
environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment
variable DJANGO_SETTINGS_MODULE is undefined.



Here is the content of manage.py file


*#!/usr/bin/env python*
*import os*
*import sys*
*
*
*if __name__ == "__main__":*
*os.environ.setdefault("DJANGO_SETTINGS_MODULE",
"firstjango.settings")*
*
*
*from django.core.management import execute_from_command_line*
*
*
*execute_from_command_line(sys.argv)*


---

Here is the error which i received after executing export
DJANGO_SETTINGS_MODULE=__"path to project"


--__--__
kbjp@kbjp-VGN-CS35GN-B:~/__Desktop/kbproject/firstjango$ export
DJANGO_SETTINGS_MODULE=__firstjango.settings
kbjp@kbjp-VGN-CS35GN-B:~/__Desktop/kbproject/firstjango$
django-admin.py syncdb
Traceback (most recent call last):
   File "/usr/local/bin/django-admin.__py", line 5, in 
 management.execute_from___command_line()
   File

"/usr/local/lib/python2.7/__dist-packages/django/core/__management/__init__.py",
line 443, in execute_from_command_line
 utility.execute()
   File

"/usr/local/lib/python2.7/__dist-packages/django/core/__management/__init__.py",
line 382, in execute
 self.fetch_command(subcommand)__.run_from_argv(self.argv)
   File

"/usr/local/lib/python2.7/__dist-packages/django/core/__management/__init__.py",
line 261, in fetch_command
 klass = load_command_class(app_name, subcommand)
   File

"/usr/local/lib/python2.7/__dist-packages/django/core/__management/__init__.py",
line 69, in 

Re: Django environment setup path problem

2013-02-13 Thread Bill Freeman
How are you invoking manage.py?  Try cd'ing to the directory containing it
before running it and see if that helps.  (That directory will then
automatically be on python's sys.path, which is needed.
DJANGO_SETTINGS_MODULE must be a python style package.module style path,
not a filesystem path, so depending on what yout mean by "path to project"
I wouldn't expect your second approach to work either.)

On Wed, Feb 13, 2013 at 1:57 AM, kulbhushan patariya <
kulbhushan4...@gmail.com> wrote:

> Hi,
> I have following problem regarding Django.
> Can anyone help me out
> --**--**
> -
> kbjp@kbjp-VGN-CS35GN-B:~/**Desktop/kbproject/firstjango$ django-admin.py
> syncdb
> Traceback (most recent call last):
>   File "/usr/local/bin/django-admin.**py", line 5, in 
> management.execute_from_**command_line()
>   File 
> "/usr/local/lib/python2.7/**dist-packages/django/core/**management/__init__.py",
> line 443, in execute_from_command_line
> utility.execute()
>   File 
> "/usr/local/lib/python2.7/**dist-packages/django/core/**management/__init__.py",
> line 382, in execute
> self.fetch_command(subcommand)**.run_from_argv(self.argv)
>   File 
> "/usr/local/lib/python2.7/**dist-packages/django/core/**management/__init__.py",
> line 261, in fetch_command
> klass = load_command_class(app_name, subcommand)
>   File 
> "/usr/local/lib/python2.7/**dist-packages/django/core/**management/__init__.py",
> line 69, in load_command_class
> module = import_module('%s.management.**commands.%s' % (app_name,
> name))
>   File "/usr/local/lib/python2.7/**dist-packages/django/utils/**importlib.py",
> line 35, in import_module
> __import__(name)
>   File "/usr/local/lib/python2.7/**dist-packages/django/core/**
> management/commands/syncdb.py"**, line 8, in 
> from django.core.management.sql import custom_sql_for_model,
> emit_post_sync_signal
>   File 
> "/usr/local/lib/python2.7/**dist-packages/django/core/**management/sql.py",
> line 6, in 
> from django.db import models
>   File "/usr/local/lib/python2.7/**dist-packages/django/db/__**init__.py",
> line 11, in 
> if DEFAULT_DB_ALIAS not in settings.DATABASES:
>   File 
> "/usr/local/lib/python2.7/**dist-packages/django/utils/**functional.py",
> line 184, in inner
> self._setup()
>   File "/usr/local/lib/python2.7/**dist-packages/django/conf/__**init__.py",
> line 40, in _setup
> raise ImportError("Settings cannot be imported, because environment
> variable %s is undefined." % ENVIRONMENT_VARIABLE)
> ImportError: Settings cannot be imported, because environment variable
> DJANGO_SETTINGS_MODULE is undefined.
>
>
>
> Here is the content of manage.py file
>
> 
> *#!/usr/bin/env python*
> *import os*
> *import sys*
> *
> *
> *if __name__ == "__main__":*
> *os.environ.setdefault("DJANGO_SETTINGS_MODULE",
> "firstjango.settings")*
> *
> *
> *from django.core.management import execute_from_command_line*
> *
> *
> *execute_from_command_line(sys.argv)*
>
>
> ---
>
> Here is the error which i received after executing export
> DJANGO_SETTINGS_MODULE=**"path to project"
>
>
> --**--**
> kbjp@kbjp-VGN-CS35GN-B:~/**Desktop/kbproject/firstjango$ export
> DJANGO_SETTINGS_MODULE=**firstjango.settings
> kbjp@kbjp-VGN-CS35GN-B:~/**Desktop/kbproject/firstjango$ django-admin.py
> syncdb
> Traceback (most recent call last):
>   File "/usr/local/bin/django-admin.**py", line 5, in 
> management.execute_from_**command_line()
>   File 
> "/usr/local/lib/python2.7/**dist-packages/django/core/**management/__init__.py",
> line 443, in execute_from_command_line
> utility.execute()
>   File 
> "/usr/local/lib/python2.7/**dist-packages/django/core/**management/__init__.py",
> line 382, in execute
> self.fetch_command(subcommand)**.run_from_argv(self.argv)
>   File 
> "/usr/local/lib/python2.7/**dist-packages/django/core/**management/__init__.py",
> line 261, in fetch_command
> klass = load_command_class(app_name, subcommand)
>   File 
> "/usr/local/lib/python2.7/**dist-packages/django/core/**management/__init__.py",
> line 69, in load_command_class
> module = import_module('%s.management.**commands.%s' % (app_name,
> name))
>   File "/usr/local/lib/python2.7/**dist-packages/django/utils/**importlib.py",
> line 35, in import_module
> __import__(name)
>   File "/usr/local/lib/python2.7/**dist-packages/django/core/**
> management/commands/syncdb.py"**, line 8, in 
> from django.core.management.sql import custom_sql_for_model,
> emit_post_sync_signal
>   File 
> "/usr/local/lib/python2.7/**dist-packages/django/core/**management/sql.py",
> line 6, in 
> from 

Re: Has the djangoproject.com site been down?

2013-02-13 Thread +Emmanuel
Thanks y'all. I'll try other options.

On Tuesday, February 12, 2013 7:40:17 PM UTC+3, +Emmanuel wrote:
>
> Is it just me or is djangoproject.com not loading? Been trying to access 
> it for a couple of weeks without success. I've tried different browsers to 
> no avail. Am accessing it from Africa.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django 1.5 AbstractBaseUser with char primary key not JSON serializable

2013-02-13 Thread Kaloian

Hi Russell,


Thanks for the responce! I actually found the problem it was not where I 
was looking for it and it was more of a typo. 
And your suggestion No.2 appears to be right:

> * Do you have any models with foreign keys to your custom user? (i.e., is 
> the problem manifesting when serialising Merchant, or serialising foreign 
> keys to Merchant?)
>

I am having a Product model with foreignkey to the Merchant model which had 
natural key method defined as follows:

class Product(models.Model):
name = models.CharField(max_length=200)
#merchant = models.ForeignKey(Merchant, to_field='api_key')
merchant = models.ForeignKey(Merchant)
url = models.URLField(max_length = 2000)  
description = models.TextField(blank=True) 
client_product_id = models.CharField(max_length='100')

objects = ProductManager() 
class Meta:
verbose_name = 'Product'
verbose_name_plural = 'Products' 
unique_together = ('merchant', 'client_product_id',) 

def __unicode__(self):
return self.name 
  
def natural_key(self):
return (self.merchant, self.client_product_id) 

The natural_key method returned self.merchant instead of self.merchant_id 
so it was trying to serialize the whole merchant object to make a natural 
key.  After switching this to merchant_id it is working properly. 

As a side note -- if you're using email as your username field, you should 
> set it as unique=True -- USERNAME_FIELD needs to be unique or you'll 
> experience problems later on. This is something that should probably be 
> caught by validation - which is a bug deserving of it's own report. For 
> performance reasons, you also probably want to set it db_index=True, since 
> you're going to be searching on that field fairly often, so having an index 
> on it makes sense.
>

Thanks for the notes I will for sure add these, but shouldn't both(unique 
and db_index) be added by default when you set your USERNAME_FIELD . 

Regards,
Kaloian 






On Wednesday, February 13, 2013 3:04:47 AM UTC+2, Russell Keith-Magee wrote:
>
>
> On Tue, Feb 12, 2013 at 9:03 PM, Kaloian  > wrote:
>
>> I am having the following custom user model trying to use the Django 1.5 
>> AbstractBaseUser:
>>
>> class Merchant(AbstractBaseUser): 
>> email = models.EmailField()
>> company_name = models.CharField(max_length=256)
>> website = models.URLField()
>> description = models.TextField(blank=True)
>> api_key = models.CharField(blank=True, max_length=256, primary_key=True) 
>>   
>>
>> USERNAME_FIELD = 'email' 
>> REQUIRED_FIELDS = ['company_name','website']
>>
>>
>>class Meta:
>> verbose_name = _('Merchant')
>> verbose_name_plural = _('Merchants')
>>
>>def __unicode__(self):
>> return self.company_name 
>>
>>
>> The model works perfectly and database is as expected, but the problem is 
>> when I try to dumpdata to create fixtures for my tests. 
>>
>> python manage.py dumpdata --natural --exclude=contenttypes 
>> --exclude=auth.permission --indent=4 > fixtures/initial_data.json
>>
>>
>> Then I get the error:
>>
>> CommandError: Unable to serialize database:  is not 
>> JSON serializable
>>
>>
>>
>> Do you have ideas what could be the reason for this. Could it be the 
>> charfield primary key or something with the abstractbaseuser model?
>>
>> It's not immediately clear. The use of natural keys could also be a 
> contributing factor here. 
>
> What you've described isn't a problem I've seen previously, so you should 
> open a ticket to track it. It would also be exceedingly helpful if you can 
> try running a few tests to remove possible causes - e.g., 
>
>  * Does serialising *without* natural keys work? 
>  * Do you have any models with foreign keys to your custom user? (i.e., is 
> the problem manifesting when serialising Merchant, or serialising foreign 
> keys to Merchant?)
>  * Do you still have problems if you use a 'normal' integer key?
>
> Essentially, any help you can provide in narrowing down the exact cause 
> would be most helpful.
>
> Also, if you can run the tests with --traceback, we can get the full error 
> logs.
>
> As a side note -- if you're using email as your username field, you should 
> set it as unique=True -- USERNAME_FIELD needs to be unique or you'll 
> experience problems later on. This is something that should probably be 
> caught by validation - which is a bug deserving of it's own report. For 
> performance reasons, you also probably want to set it db_index=True, since 
> you're going to be searching on that field fairly often, so having an index 
> on it makes sense.
>
> Yours,
> Russ Magee %-)
>
>
>

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

One-to-many relationships in submission forms

2013-02-13 Thread Skip Montanaro
Refereeing to Sanjay's response to another poster's plea about recipes and 
ingredients  helped me muddle through.  I'm unclear on the form keyword arg 
referencing the base form. Using it gave me metaclass errors.

Skip

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django server ignores POST requests?

2013-02-13 Thread Bill Freeman
If the original requests aren't completing then perhaps you are running up
against some connection limit in your configuration?

On Wed, Feb 13, 2013 at 7:29 AM, Michał Nowotka  wrote:

> This is really strange behaviour. When I issue POST request to many
> times django suddenly starts to ignore them all. I can see then in
> firebug but debug server shows nothing. Restarting server doesn't
> help. Even more, when I try to restart server when this happens I
> always get:
>
> Error: That port is already in use.
>
> Restarting the whole machine helps.
>
> I thought it may be related to
>
> Exception AttributeError: AttributeError("'_DummyThread' object
> has no attribute '_Thread__block'",) in  '/usr/lib/python2.7/threading.pyc'> ignored
>
> error I'm having but event after applying workaround:
>
> import threading
> threading._DummyThread._Thread__stop = lambda x: 42
>
> described on
> http://stackoverflow.com/questions/13193278/understand-python-threading-bug
>
> I'm still having the same problem.
> I don't know ho to diagnose the source of the issue.
>
> Maybe this will be helpful:
>
> OS: ubuntu 12.04 LTS
> Processor: Intel® Core™ i7-2720QM CPU @ 2.20GHz × 4
> Python 2.7.3
> Django 1.4.1
>
> Any help would be appreciated.
>
> --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




One-to-many relationships in submission forms

2013-02-13 Thread Skip Montanaro
Can anyone point me at a complete example of using inlineformset_factory? I'm 
fine with the example in the book, as far add it goes, but it doesn't show how 
to actually use it in a Form, and my naive attempt to use it so far has come up 
empty.

Thx,

Skip

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Question from a very beginner: Include dynamic template

2013-02-13 Thread Olivier
Hi everybody, 

I'm beginner in Django, and I have a "little" problem.

I would like to include a subtemplate in a for loop and passing some 
parameter.

like this:

  {% for tasklist in object_list %}
>   
> {{ 
> tasklist.title }}
> {% block task_list %}
> {% include "tasklist-one.html" with tasklist_id=tasklist.id %}
> {% endblock %}
>   
>   {% endfor %}


But before including template ( tasklist-one.html ) I would like to call a 
function  which take the tasklist_id and look for the task which compose 
the tasklist.
How can I do this kind of things ? 

Thank you !

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django 1.5 - release date

2013-02-13 Thread Martin B.
Hmm, the list of blockers seems to be empty. Seeing as its been a while 
since the last update here, any news on a rc/stable release?

On Sunday, December 30, 2012 1:19:04 AM UTC, Russell Keith-Magee wrote:
>
>
> On Sat, Dec 29, 2012 at 2:44 PM, Aidan Zhakypov 
>  > wrote:
>
>> Does anyone know when Django 1.5 is going to be released as a stable 
>> version? If I want to *start* developing a production web site, should I 
>> write it on Django 1.4 or is it already ok to implement it on Django 1.5?
>
>
> It's difficult to give an exact date for the release of Django 1.5. We've 
> put out 2 beta releases, which means there are no more features to be 
> added; and the list of release blocking bugs is down to single figures [1]. 
>
> If I were to guess, I'd say we're less than a month from the final release 
> of 1.5. However, this is all dependent on how many new release blocking 
> bugs are discovered between now and then, and the resources that the 
> community and the core team can devote to getting the release out the door.
>
> Whether that suits your own development schedule is up to you. 
>
> The good news is that unless you're planning to use a new feature from 1.5 
> (e.g., pluggable User models), it shouldn't really matter whether you start 
> developing using Django 1.4 or Django 1.5. Django has a strict backwards 
> compatibility policy, so the migration process from 1.4 to 1.5 should be 
> very smooth.
>
> [1] 
> https://code.djangoproject.com/query?status=assigned=new=reopened=Release+blocker
>
> Yours,
> Russ Magee %-)
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Django environment setup path problem

2013-02-13 Thread kulbhushan patariya
Hi,
I have following problem regarding Django.
Can anyone help me out 
-
kbjp@kbjp-VGN-CS35GN-B:~/Desktop/kbproject/firstjango$ django-admin.py 
syncdb
Traceback (most recent call last):
  File "/usr/local/bin/django-admin.py", line 5, in 
management.execute_from_command_line()
  File 
"/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", 
line 443, in execute_from_command_line
utility.execute()
  File 
"/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", 
line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", 
line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
  File 
"/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", 
line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", 
line 35, in import_module
__import__(name)
  File 
"/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py",
 
line 8, in 
from django.core.management.sql import custom_sql_for_model, 
emit_post_sync_signal
  File 
"/usr/local/lib/python2.7/dist-packages/django/core/management/sql.py", 
line 6, in 
from django.db import models
  File "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 
11, in 
if DEFAULT_DB_ALIAS not in settings.DATABASES:
  File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", 
line 184, in inner
self._setup()
  File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", 
line 40, in _setup
raise ImportError("Settings cannot be imported, because environment 
variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable 
DJANGO_SETTINGS_MODULE is undefined.



Here is the content of manage.py file

*#!/usr/bin/env python*
*import os*
*import sys*
*
*
*if __name__ == "__main__":*
*os.environ.setdefault("DJANGO_SETTINGS_MODULE", "firstjango.settings")*
*
*
*from django.core.management import execute_from_command_line*
*
*
*execute_from_command_line(sys.argv)*

---

Here is the error which i received after executing export 
DJANGO_SETTINGS_MODULE="path 
to project"



kbjp@kbjp-VGN-CS35GN-B:~/Desktop/kbproject/firstjango$ export 
DJANGO_SETTINGS_MODULE=firstjango.settings
kbjp@kbjp-VGN-CS35GN-B:~/Desktop/kbproject/firstjango$ django-admin.py 
syncdb
Traceback (most recent call last):
  File "/usr/local/bin/django-admin.py", line 5, in 
management.execute_from_command_line()
  File 
"/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", 
line 443, in execute_from_command_line
utility.execute()
  File 
"/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", 
line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", 
line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
  File 
"/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", 
line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", 
line 35, in import_module
__import__(name)
  File 
"/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py",
 
line 8, in 
from django.core.management.sql import custom_sql_for_model, 
emit_post_sync_signal
  File 
"/usr/local/lib/python2.7/dist-packages/django/core/management/sql.py", 
line 6, in 
from django.db import models
  File "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 
11, in 
if DEFAULT_DB_ALIAS not in settings.DATABASES:
  File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", 
line 184, in inner
self._setup()
  File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", 
line 42, in _setup
self._wrapped = Settings(settings_module)
  File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", 
line 95, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): 
%s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'firstjango.settings' (Is it on 
sys.path?): No module named firstjango.settings
kbjp@kbjp-VGN-CS35GN-B:~/Desktop/kbproject/firstjango$ 

-- 

Is Django is suitable fame work to develop a web application which uses HIVE

2013-02-13 Thread Shreedhar Naik
We are planning to use Django to develope a web application which query to 
HIVE and get the data.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Questions about vim

2013-02-13 Thread Yussi

Thank you i am stealing lines from you right now, very nice setup you have.

On 12/02/13 20:21, Antoni Aloy wrote:

I have created my own collection of plugins for my django and Python
work with vim: autocomplete, sysntax check, templates, etc. This is
mine: http://code.google.com/p/trespams-vim/ but there are others like
https://github.com/fisadev/fisa-vim-config or
http://sontek.net/blog/detail/turning-vim-into-a-modern-python-ide


2013/2/12 Yussi >

On 12/02/13 14:52, Ryan Nowakowski wrote:

On Tue, Feb 12, 2013 at 11:22:54AM +, Yussi wrote:

Hi,
I was wondering if there are any vim users here who managed
to get a
productive working environment for django here.

I looked at the manuals, and set myself up with tags, omni
complete,
and syntax error check, but it's far from ideal. omni
complete fails
to guess the context correctly most of the time, and is
otherwise
lacking what I expect from an ide, namely I would like to be
able to
see function headers when typing so I know what arguments to
give
it,I would like some short cuts for local variables, I would
like
some easy vim templates for things like CharField, DateField
etc, I
am still new to django, and i really don't remember enough
to free
code everything.

any other tip of using vim with django would be appreciated.


I have vim configured with ctags and cscope.  Once I have that
set up
correctly, I use ctags to jump from any use of CharField to the
actual
Django source code for CharField.  That, of course, shows me the
arguments
required and the docstring.


Thanks, I actually had ctags, but rarely used it.


--
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+unsubscribe@__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?hl=en
.
For more options, visit https://groups.google.com/__groups/opt_out
.





--
Antoni Aloy López
Blog: http://trespams.com
Site: http://apsl.net

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




django server ignores POST requests?

2013-02-13 Thread Michał Nowotka
This is really strange behaviour. When I issue POST request to many
times django suddenly starts to ignore them all. I can see then in
firebug but debug server shows nothing. Restarting server doesn't
help. Even more, when I try to restart server when this happens I
always get:

Error: That port is already in use.

Restarting the whole machine helps.

I thought it may be related to

Exception AttributeError: AttributeError("'_DummyThread' object
has no attribute '_Thread__block'",) in  ignored

error I'm having but event after applying workaround:

import threading
threading._DummyThread._Thread__stop = lambda x: 42

described on 
http://stackoverflow.com/questions/13193278/understand-python-threading-bug

I'm still having the same problem.
I don't know ho to diagnose the source of the issue.

Maybe this will be helpful:

OS: ubuntu 12.04 LTS
Processor: Intel® Core™ i7-2720QM CPU @ 2.20GHz × 4
Python 2.7.3
Django 1.4.1

Any help would be appreciated.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Has the djangoproject.com site been down?

2013-02-13 Thread Sanjay Bhangar
for future reference, I find http://downforeveryoneorjustme.com/ to be
quite useful for checking this sort of thing

On Wed, Feb 13, 2013 at 5:12 PM, Babatunde Akinyanmi
 wrote:
> Its not just you, at least when I'm not trying with my phone.
>
> ..and say your from Nigeria not Africa
>
> Sent from my Windows Phone
> 
> From: tOlorun
> Sent: 2/12/2013 5:53 PM
> To: django-users@googlegroups.com
> Subject: Re: Has the djangoproject.com site been down?
>
> its just you ...
> its loading here ...
> Thanks
> tOlorun
>
> *Oluwanife@me*
>
>
> To be filled with the life of Christ Jesus and released into our
> destinies,taking
> the world for Him.
>
> | M: +2348121631706 | M: +234817907 | M: +23233487811
> | E-mail: omnioto...@gmail.com I omnioto...@live.com |
> omnioto...@yahoo.co.uk
> | Skype: omniotosho
>
>
> On Tue, Feb 12, 2013 at 5:40 PM, +Emmanuel  wrote:
>>
>> Is it just me or is djangoproject.com not loading? Been trying to access
>> it for a couple of weeks without success. I've tried different browsers to
>> no avail. Am accessing it from Africa.
>>
>> --
>> 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?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>
>
> --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
> --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




RE: Has the djangoproject.com site been down?

2013-02-13 Thread Babatunde Akinyanmi
Its not just you, at least when I'm not trying with my phone.

..and say your from Nigeria not Africa

Sent from my Windows Phone
--
From: tOlorun
Sent: 2/12/2013 5:53 PM
To: django-users@googlegroups.com
Subject: Re: Has the djangoproject.com site been down?

its just you ...
its loading here ...
Thanks
tOlorun

*Oluwanife@me*


To be filled with the life of Christ Jesus and released into our
destinies,taking
the world for Him.

| M: +2348121631706 | M: +234817907 | M: +23233487811
| E-mail: omnioto...@gmail.com I omnioto...@live.com |
omnioto...@yahoo.co.uk
| Skype: omniotosho


On Tue, Feb 12, 2013 at 5:40 PM, +Emmanuel  wrote:

> Is it just me or is djangoproject.com not loading? Been trying to access
> it for a couple of weeks without success. I've tried different browsers to
> no avail. Am accessing it from Africa.
>
> --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

 --
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Three forms (one should be dynamic) with relationships on the same view. Not sure how to accomplish this issue.

2013-02-13 Thread Adrián Espinosa
Hello all, I have the following models (among others):

class Project(models.Model):
client = models.ForeignKey(User)
notes = models.TextField()
service = models.CharField(max_length=25)
# more fields

class Circuit(models.Model):
pointA = models.CharField(max_length=20)
pointB = models.CharField(max_length=20)
# more fields

class Union(models.Model):
project = models.ForeignKey(Project)
circuit = models.ForeignKey(Circuit)
tdm = models.ForeignKey(Voip)
type = models.CharField(max_length=5)
# more fields

class Attachment(models.Model):
project = models.ForeignKey(Project)
docfile = models.FileField(...)
# more fields


One project can have several circuits (this is a service, as well as for 
example Voip), and one circuit can belong to several projects, so it's a 
M-N relationship.
In my view, I need to show the ModelForm of Project and Form of Attachment 
(easy for now) and depending on the value of the field 'service', load the 
next form into an iframe (it's an idea). For example, if they choose 
Circuit, load ModelForm of Circuit, if is voip is chosen load ModelForm of 
Voip, etc.

My doubt and issue here is how to accomplish this, because I would need to 
save both items first (Project and Circuit) and then create a new entry in 
Union model with the corresponding IDs and I don't know how can I retrieve 
the IDs in this case.

It would be like:
1. Save Circuit (store the id somewhere)
2. Save Project (store the id somewhere)
3. New entry in Union (circuit_id, project_id)

Maybe I'm overthinking this, but I do not see a clear solution

Thank you very much in advance for the 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.