IntegrityError when creating a brand new model instance

2013-02-07 Thread Some Developer
I have a model for a Tag object with simply has two fields. A title 
(which has the unique constraint) and a description. I also have a 
FormView based view class which handles the creation of Tag objects.


When I try and save the object in the form_valid() method I always get 
an IntegrityError stating that the title column is not unique. This is 
somewhat puzzling as I have deleted the SQLite database file and 
recreated it using syncdb / migrate so it is completely empty.


I'm completely baffled by this error.

--
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: post_save signal getting called twice !

2013-02-07 Thread vijay shanker
Thanks Evans.That was helpful. :)

On Thursday, February 7, 2013 7:54:36 PM UTC+5:30, Tom Evans wrote:
>
> On Thu, Feb 7, 2013 at 1:54 PM, vijay shanker 
>  
> wrote: 
> > Hi 
> > I am using django version 1.4.3 
> > I am using two signals in my models.py 
> > one is m2m_changed, so i can have a counter field (numcounter) of number 
> of 
> > m2m fields attached, and another is post_save so i can decide whether to 
> > have a OneToOneField (cartrule, is to be applied only if there are more 
> than 
> > 2 fields) or not. 
> > my models.py is: 
> > 
> > class CartItem(models.Model): 
> > content_type= models.ForeignKey(ContentType) 
> > object_id   = models.PositiveIntegerField() 
> > content_object  = generic.GenericForeignKey(' 
> > content_type','object_id') 
> > quantity= models.PositiveIntegerField(default=0) 
> > is_abandoned= models.BooleanField(default=False) 
> > created_at  = models.DateTimeField(auto_now_add=True) 
> > update_at   = models.DateTimeField(auto_now=True) 
> > def __str__(self): 
> > return self.content_object.name 
> > 
> > class CartRule(models.Model): 
> > ##some field 
> > pass 
> > 
> > class Cart(models.Model): 
> > cart_id = models.CharField(max_length=50, null=False) 
> > customer= 
> models.ForeignKey(Customer,null=True,blank=True) 
> > cartitems   = models.ManyToManyField(CartItem,null=True) 
> > created_at  = models.DateTimeField(auto_now_add=True) 
> > update_at   = models.DateTimeField(auto_now=True) 
> > cartrule   = 
> > models.OneToOneField(crapclass,null=True,blank=True) 
> > num_cartitem= models.IntegerField() 
> > def __str__(self): 
> > return self.cart_id 
> > 
> > @receiver(post_save, sender=Cart) 
> > def apply_condition(sender,instance,created,raw,using,*args,**kwargs): 
> > # i want to decide here if num_cartitem is greater than 2 its ok to 
> have 
> > a cartrule 
> > pass 
> > 
> > @receiver(m2m_changed) 
> > def save_cartitem_counter(sender, instance, signal,*args, **kwargs): 
> > if kwargs['action'] == 'post_add': 
> > instance.num_cartitem = instance.cartitems.all().count() 
> > instance.save() 
> > 
> > the issue is apply_condition gets called twice, with similar value of 
> args, 
> > first with older value of m2m (cartitem) field in Cart, the other time 
> with 
> > the values i intended to save 
> > I looked into older post but still could not figure out the whys.How 
> should 
> > i go about this ? 
> > 
>
> When you save a Cart instance, the post_save signal is triggered. 
> If the M2M relationship is changed as well, then the m2m_changed 
> signal is triggered. Your handler for this then re-saves the Cart 
> instance after denormalising data, which triggers the post save signal 
> for a second time. 
> You should probably connect the M2M receiver to a specific sender too, 
> currently it will fire whenever any M2M on any model is changed. 
>
> Keeping denormalized data like that is a pain, could you do without 
> it, and re-calculate it where necessary? 
>
> Alternatively, you could use a named intermediary M2M relationship: 
>
>
> https://docs.djangoproject.com/en/1.4/topics/db/models/#intermediary-manytomany
>  
>
> and connect signals on post_create and post_delete to the intermediary 
> model, updating the Cart as necessary. 
>
> This is a little more logical, since you wish to denormalise the data 
> whenever an item is added to or removed from a cart, ie whenever a row 
> is added or deleted to the intermediate table. Naming the relationship 
> allows you to connect the signals to the right place. 
>
> Cheers 
>
> Tom 
>

-- 
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: Why doesn't form_valid() in FormView take a request argument?

2013-02-07 Thread Rainy


On Thursday, February 7, 2013 3:39:43 AM UTC-5, Some Developer wrote:
>
> On 06/02/13 23:00, Rainy wrote: 
> > On Wednesday, February 6, 2013 3:09:39 PM UTC-5, Some Developer wrote: 
> > 
> > Why doesn't the form_valid() (and for that matter the 
> form_invalid()) 
> > method in the FormView generic class based view take a request 
> > argument? 
> > 
> > I've found that if you have a form which requires you to override 
> the 
> > form_valid() method because you need to do custom logic before you 
> save 
> > the model and you need to save the user ID of the person who posted 
> the 
> > form you need to also override the post() method in order to pass on 
> > the 
> > correct data by manually adding it to the post argument of the 
> > form_valid() method by using request.user. 
> > 
> > Am I missing something here? Is there any easier way to achieve what 
> I 
> > want to achieve? 
> > 
> > 
> > 
> > How about using self.request attribute?  -rainy 
>
> Heh I don't know how I missed that. Thanks, that solves a couple of 
> issues :). 
>
> I'm in the process of converting some old code to class based views and 
> am still getting used to using them. 
>
>

No problem. There's of course also self.args and self.kwargs.

If you need to use views that inherit from multiple CBVs, take
a look at my tutorial that uses modified GCBVs:

http://lightbird.net/dbe2/

(I will add more tutorials in near future)

HTH, -rainy 

-- 
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: Access to data via many-to-many while in save()

2013-02-07 Thread Mike Dewhirst

Much more clearly expressed here ...

https://docs.djangoproject.com/en/1.4/topics/db/models/#extra-fields-on-many-to-many-relationships


On 7/02/2013 5:04pm, Derek wrote:

I am trying to access the field(s) of a Child table while still inside
the save method of the Parent table.

Assuming that the many-to-many field in the Parent table is called
`m2m_field`, and the field I need to access in the Child table is
called `child_field`, what I have tried is this:


What I think you need in the Parent model is access to the "through" table - 
say Parent_Child - which has a foreign key to both Parent and Child called 
Parent_Child.parent and Parent_Child.child respectively.

Like this ...

class Parent(models.Model):
child = models.ManyToManyField('Child',  through='Parent_Child')
#
..
def save(self, *args, **kwargs):
obj_qs = Parent_Child.objects.filter(parent=self)
# which gives you a query set to play with and extract obj
# or if you know the child object
# obj = Parent_Child.objects.get(parent=self, child=whatever)
# which gives you obj
# then ...
data_I_need = obj.thingummy
super(Parent, self).save(*args, **kwargs)

This is not necessarily the correct way to do things. I think there might be 
Django shortcut but I'm not immediately familiar with it. I'd have to read the 
query docs.

Mike



def save_model(self, request, obj, form, change):
 # save object and the many-to-many data
 obj.save()
 # this does not work:
 data_I_need = obj.m2m.all()[0].child_field
 # nor does this:
 data_I_need = Parent.objects.get(pk=obj.pk).m2m.all()[0].child_field
 # in fact, length is 0, so no data in the set...
 print len(Parent.objects.get(pk=obj.pk).m2m.all())

I know I am not grasping some key aspect of the problem; but I cannot
see what it is, and would appreciate any help with this problem!

Thanks
Derek





--
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 and mod_wsgi serving different apps from separate virtual hosts on the same server

2013-02-07 Thread Sam Solomon
Glad you figured it out!


On Thu, Feb 7, 2013 at 2:55 PM, robertlnewman wrote:

> Just thought I would wrap this up. Turns out the problem was that my
> sysadmin did not have the port I wanted (8788) open to traffic. My syntax
> was correct. The problem was a network one.
>
> Sam - I sincerely appreciate your help in (a) verifying that my syntax
> looked good, and (b) describing some new ways of setting up mod_wsgi.
>
> - Rob
>
> On Feb 7, 2013, at 1:23 PM, robertlnewman wrote:
>
> Okay no worries. Just thought you might have had some mod_wsgi 'secret
> sauce'.
>
> Graham Dumpleton himself acknowledges that the docs for mod_wsgi are
> outdated in some respects (see the comments at the foot of his 
> article),
> so you never know.
>
> Thanks again. I appreciate your time.
> - Rob
>
> On Feb 7, 2013, at 1:15 PM, Sam Solomon wrote:
>
> Regarding having WSGIDaemonProcess outside of vhosts, as explained in the
> comment I added, it allows you to use the same process to handle requests
> from multiple vhosts.
>
> As for the rest, I honestly don't remember why or where they came from, I
> just know that this is probably not all that common (multiple vhosts with
> different mod_wsgi processes) so sent whatever we have that works in hopes
> that it'll work for you. Unfortunately I have forgotten how exactly all of
> this works together.
>
> On Thu, Feb 7, 2013 at 1:07 PM, robertlnewman wrote:
>
>> Thanks for the reply. Very interesting. So you define each
>> WSGIDaemonProcess outside of the vhosts and then call it from within the
>> vhost block? What is the advantage of that? Or is it just 6-of-one,
>> half-a-dozen of another?
>>
>> Also, I notice that you are passing a bunch more args to WSGIScriptAlias
>> (process-group, application-group). I don't see these as available options
>> in the mod_wsgi docs (
>> http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives). The only
>> option I see that you can pass to WSGIScriptAlias is the URL-path and the
>> file-path or directory-path:
>> http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIScriptAlias
>>
>
>  --
> 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: Django and mod_wsgi serving different apps from separate virtual hosts on the same server

2013-02-07 Thread robertlnewman
Just thought I would wrap this up. Turns out the problem was that my sysadmin 
did not have the port I wanted (8788) open to traffic. My syntax was correct. 
The problem was a network one.

Sam - I sincerely appreciate your help in (a) verifying that my syntax looked 
good, and (b) describing some new ways of setting up mod_wsgi.

- Rob

On Feb 7, 2013, at 1:23 PM, robertlnewman wrote:

> Okay no worries. Just thought you might have had some mod_wsgi 'secret 
> sauce'. 
> 
> Graham Dumpleton himself acknowledges that the docs for mod_wsgi are outdated 
> in some respects (see the comments at the foot of his article), so you never 
> know.
> 
> Thanks again. I appreciate your time.
> - Rob
> 
> On Feb 7, 2013, at 1:15 PM, Sam Solomon wrote:
> 
>> Regarding having WSGIDaemonProcess outside of vhosts, as explained in the 
>> comment I added, it allows you to use the same process to handle requests 
>> from multiple vhosts.
>> 
>> As for the rest, I honestly don't remember why or where they came from, I 
>> just know that this is probably not all that common (multiple vhosts with 
>> different mod_wsgi processes) so sent whatever we have that works in hopes 
>> that it'll work for you. Unfortunately I have forgotten how exactly all of 
>> this works together.
>> 
>> On Thu, Feb 7, 2013 at 1:07 PM, robertlnewman  
>> wrote:
>> Thanks for the reply. Very interesting. So you define each WSGIDaemonProcess 
>> outside of the vhosts and then call it from within the vhost block? What is 
>> the advantage of that? Or is it just 6-of-one, half-a-dozen of another?
>> 
>> Also, I notice that you are passing a bunch more args to WSGIScriptAlias 
>> (process-group, application-group). I don't see these as available options 
>> in the mod_wsgi docs 
>> (http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives). The only 
>> option I see that you can pass to WSGIScriptAlias is the URL-path and the 
>> file-path or directory-path: 
>> http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIScriptAlias

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




Appscale and Django

2013-02-07 Thread Henrik Genssen
Hi all,

is someone on the list using Appscale [1] with Django?
If yes, what is your setup (MySQL, Mongo, E2, Eucalyptus [2], KVM, etc.)
What is your experiance towards stalability, reliability and performance?

[1] http://appscale.cs.ucsb.edu
[2] http://www.eucalyptus.com

regards

Henrik

-- 
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 and mod_wsgi serving different apps from separate virtual hosts on the same server

2013-02-07 Thread robertlnewman
Okay no worries. Just thought you might have had some mod_wsgi 'secret sauce'. 

Graham Dumpleton himself acknowledges that the docs for mod_wsgi are outdated 
in some respects (see the comments at the foot of his article), so you never 
know.

Thanks again. I appreciate your time.
- Rob

On Feb 7, 2013, at 1:15 PM, Sam Solomon wrote:

> Regarding having WSGIDaemonProcess outside of vhosts, as explained in the 
> comment I added, it allows you to use the same process to handle requests 
> from multiple vhosts.
> 
> As for the rest, I honestly don't remember why or where they came from, I 
> just know that this is probably not all that common (multiple vhosts with 
> different mod_wsgi processes) so sent whatever we have that works in hopes 
> that it'll work for you. Unfortunately I have forgotten how exactly all of 
> this works together.
> 
> On Thu, Feb 7, 2013 at 1:07 PM, robertlnewman  wrote:
> Thanks for the reply. Very interesting. So you define each WSGIDaemonProcess 
> outside of the vhosts and then call it from within the vhost block? What is 
> the advantage of that? Or is it just 6-of-one, half-a-dozen of another?
> 
> Also, I notice that you are passing a bunch more args to WSGIScriptAlias 
> (process-group, application-group). I don't see these as available options in 
> the mod_wsgi docs 
> (http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives). The only 
> option I see that you can pass to WSGIScriptAlias is the URL-path and the 
> file-path or directory-path: 
> http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIScriptAlias
> 
> 
> 
> -- 
> 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: Django and mod_wsgi serving different apps from separate virtual hosts on the same server

2013-02-07 Thread Sam Solomon
Regarding having WSGIDaemonProcess outside of vhosts, as explained in the
comment I added, it allows you to use the same process to handle requests
from multiple vhosts.

As for the rest, I honestly don't remember why or where they came from, I
just know that this is probably not all that common (multiple vhosts with
different mod_wsgi processes) so sent whatever we have that works in hopes
that it'll work for you. Unfortunately I have forgotten how exactly all of
this works together.

On Thu, Feb 7, 2013 at 1:07 PM, robertlnewman wrote:

> Thanks for the reply. Very interesting. So you define each
> WSGIDaemonProcess outside of the vhosts and then call it from within the
> vhost block? What is the advantage of that? Or is it just 6-of-one,
> half-a-dozen of another?
>
> Also, I notice that you are passing a bunch more args to WSGIScriptAlias
> (process-group, application-group). I don't see these as available options
> in the mod_wsgi docs (
> http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives). The only
> option I see that you can pass to WSGIScriptAlias is the URL-path and the
> file-path or directory-path:
> http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIScriptAlias
>

-- 
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 and mod_wsgi serving different apps from separate virtual hosts on the same server

2013-02-07 Thread robertlnewman
Hi Sam,

Thanks for the reply. Very interesting. So you define each WSGIDaemonProcess 
outside of the vhosts and then call it from within the vhost block? What is the 
advantage of that? Or is it just 6-of-one, half-a-dozen of another?

Also, I notice that you are passing a bunch more args to WSGIScriptAlias 
(process-group, application-group). I don't see these as available options in 
the mod_wsgi docs 
(http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives). The only 
option I see that you can pass to WSGIScriptAlias is the URL-path and the 
file-path or directory-path: 
http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIScriptAlias

Are you using some undocumented features?

Thanks again,
- Rob

On Feb 7, 2013, at 12:02 PM, Sam Solomon wrote:

> Can't spot any issues but here is what we have to run multiple staging 
> versions of our site:
> 
> group_* names are more descriptive in the actual settings
> 
> WSGIDaemonProcess group_1 processes=1 threads=100 display-name=%{GROUP} 
> inactivity-timeout=30 #defining it out here allows you to use the same 
> proccess group for multiple vhosts if you did have a few duplicates.
> 
> 
> WSGIProcessGroup group_1
> WSGIScriptAlias / /path/to/staging_django.wsgi \
> process-group=group_1 application-group=%{GLOBAL} #I'm actually guessing 
> that one of these is redundant, but you probably need at least one reference 
> to the group.
> 
> 
> WSGIDaemonProcess group_2 processes=1 threads=100 display-name=%{GROUP} 
> inactivity-timeout=30vhosts if you did have a few duplicates.
> 
> 
> WSGIProcessGroup group_2
> WSGIScriptAlias / /path/to/staging_2_django.wsgi \
> process-group=group_2 application-group=%{GLOBAL}
> 
> 
> 
> On Wednesday, February 6, 2013 12:05:39 PM UTC-8, Rob Newman wrote:
> Hi fellow Django devs,
> 
> I have been going around and around trying to figure this out for 2 days, 
> without success. I am trying to serve two Django sites from one webserver 
> using Apache's virtual hosts. The first works, the second doesn't. (Note that 
> I have been happily serving Django content via mod_wsgi on Apache for one 
> virtual host for the better part of a year already, so I am not a newbie.)
> 
> For background we are running Django 1.4.2 within a virtualenv and serving 
> via Apache 2.2.
> 
> We have one project directory '/path/to/django/www' where all our apps live. 
> I have all my settings and wsgi files for each site in:
> 
> /path/to/django/www/site1/settings
> /path/to/django/www/site1/apache
> 
> and
> 
> /path/to/django/www/site2/settings
> /path/to/django/www/site2/apache
> 
> I have my apps in '/path/to/django/www' called (for example) Foo, Bar and Baz
> 
> I want to serve apps Foo and Bar from port 8787 and app Baz from port 8788. I 
> want them all to have their content updated via one admin interface on port 
> 8787.
> 
> I suspect it has to do with https://code.djangoproject.com/ticket/18518 so I 
> have configured Django to run in mod_wsgi daemon mode. I followed the 
> instructions here and here and also read Graham Dumpleton's blog post on the 
> topic here but it still doesn't work. I am turning to this discussion group 
> as a last resort.
> 
> Here are my Apache virtual host containers:
> 
> ###
> # Start Python WSGI configurations
> 
> Listen 8787
> NameVirtualHost *:8787
> 
> 
>   DocumentRoot  /path/to/django/www/site1
>   ErrorLog "/path/to/django-8787-error_log"
>   LogLevel info
>   WSGIDaemonProcess  django-site1
>   WSGIScriptAlias / /path/to/django/www/site1/apache/django.wsgi
> 
> 
> Listen 8788
> NameVirtualHost *:8788
> 
> 
>   DocumentRoot  /path/to/django/www/site2
>   ErrorLog "/path/to/django-8788-error_log"
>   LogLevel info
>   WSGIDaemonProcess  django-site2
>   WSGIScriptAlias / /path/to/django/www/site2/apache/django.wsgi
> 
> 
> # End Python WSGI configurations
> ###
> 
> We don't run Apache from the root user (we run it as user apache) so I don't 
> AFAIK need to define anything other than a name for the WSGIDaemonProcess to 
> live under (i.e. I don't have to define the name or group options).
> 
> Here are the contents of my django.wsgi files. You can see some of my 
> experiments in trying to get this to work (lines commented out) based on the 
> tickets and documentation linked above:
> 
> site1 (site1/apache/django.wsgi)
> 
> import os, sys
> sys.path.append('/path/to/django/www/site1')
> 
> # Quick fix, but not great
> # os.environ['DJANGO_SETTINGS_MODULE'] = 'site1.settings'
> 
> # Original setting - use Apache mod_wsgi settings to control
> os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'site1.settings')
> 
> import django.core.handlers.wsgi
> application = django.core.handlers.wsgi.WSGIHandler()
> 
> site2 (site2/apache/django.wsgi)
> 
> import os, sys
> sys.path.append('/path/to/django/www/site2')
> 
> # Quick fix, but not great
> # os.environ['DJANGO_SETTINGS_MODULE'] = 

Django fixture load DeserializationError: 'unicode' object has no attribute 'pk'?

2013-02-07 Thread Kaloian
Hello,

   I am getting the following error when trying to run my tests with 
fixtures:

File 
"/usr/local/lib/python2.7/dist-packages/django/core/management/commands/loaddata.py",
 line 190, in handle
for obj in objects:
  File 
"/usr/local/lib/python2.7/dist-packages/django/core/serializers/json.py", line 
47, in Deserializerraise DeserializationError(e)DeserializationError: 'unicode' 
object has no attribute 'pk'


I am using the following to create the fixture:

manage.py dumpdata --natural --exclude=contenttypes --exclude=auth.permission 
--indent=4 > fixtures/initial_data.json 


I tried implementing natural key managers and methods for my models but 
still got the same error.

Here is the code of my models: http://pastebin.com/HbFariAC

I am really stuck with this so any clues would help me.

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.




Re: Django and mod_wsgi serving different apps from separate virtual hosts on the same server

2013-02-07 Thread Sam Solomon
Can't spot any issues but here is what we have to run multiple staging 
versions of our site:

group_* names are more descriptive in the actual settings

WSGIDaemonProcess group_1 processes=1 threads=100 display-name=%{GROUP} 
inactivity-timeout=30 #defining it out here allows you to use the same 
proccess group for multiple vhosts if you did have a few duplicates.


WSGIProcessGroup group_1
WSGIScriptAlias / /path/to/staging_django.wsgi \
process-group=group_1 application-group=%{GLOBAL} #I'm actually 
guessing that one of these is redundant, but you probably need at least one 
reference to the group.


WSGIDaemonProcess group_2 processes=1 threads=100 display-name=%{GROUP} 
inactivity-timeout=30vhosts if you did have a few duplicates.


WSGIProcessGroup group_2
WSGIScriptAlias / /path/to/staging_2_django.wsgi \
process-group=group_2 application-group=%{GLOBAL}



On Wednesday, February 6, 2013 12:05:39 PM UTC-8, Rob Newman wrote:
>
> Hi fellow Django devs,
>
> I have been going around and around trying to figure this out for 2 days, 
> without success. I am trying to serve two Django sites from one webserver 
> using Apache's virtual hosts. The first works, the second doesn't. (Note 
> that I have been happily serving Django content via mod_wsgi on Apache for 
> one virtual host for the better part of a year already, so I am not a 
> newbie.)
>
> For background we are running Django 1.4.2 within a virtualenv and serving 
> via Apache 2.2.
>
> We have one project directory '/path/to/django/www' where all our apps 
> live. I have all my settings and wsgi files for each site in:
>
> /path/to/django/www/site1/settings
> /path/to/django/www/site1/apache
>
> and
>
> /path/to/django/www/site2/settings
> /path/to/django/www/site2/apache
>
> I have my apps in '/path/to/django/www' called (for example) Foo, Bar and 
> Baz
>
> I want to serve apps Foo and Bar from port 8787 and app Baz from port 
> 8788. I want them all to have their content updated via one admin interface 
> on port 8787.
>
> I suspect it has to do with https://code.djangoproject.com/ticket/18518so I 
> have configured Django to run in mod_wsgi daemon mode. I followed the 
> instructions 
> here
>  and 
> here
>  and 
> also read Graham Dumpleton's blog post on the topic 
> here 
> but 
> it still doesn't work. I am turning to this discussion group as a last 
> resort.
>
> Here are my Apache virtual host containers:
>
> ###
> # Start Python WSGI configurations
>
> Listen 8787
> NameVirtualHost *:8787
>
> 
>   DocumentRoot  /path/to/django/www/site1
>   ErrorLog "/path/to/django-8787-error_log"
>   LogLevel info
>   WSGIDaemonProcess  django-site1
>   WSGIScriptAlias / /path/to/django/www/site1/apache/django.wsgi
> 
>
> Listen 8788
> NameVirtualHost *:8788
>
> 
>   DocumentRoot  /path/to/django/www/site2
>   ErrorLog "/path/to/django-8788-error_log"
>   LogLevel info
>   WSGIDaemonProcess  django-site2
>   WSGIScriptAlias / /path/to/django/www/site2/apache/django.wsgi
> 
>
> # End Python WSGI configurations
> ###
>
> We don't run Apache from the root user (we run it as user apache) so I 
> don't AFAIK need to define anything other than a name for the 
> WSGIDaemonProcess to live under (i.e. I don't have to define the name or 
> group options).
>
> Here are the contents of my django.wsgi files. You can see some of my 
> experiments in trying to get this to work (lines commented out) based on 
> the tickets and documentation linked above:
>
> *site1 (site1/apache/django.wsgi)*
>
> import os, sys
> sys.path.append('/path/to/django/www/site1')
>
> # Quick fix, but not great
> # os.environ['DJANGO_SETTINGS_MODULE'] = 'site1.settings'
>
> # Original setting - use Apache mod_wsgi settings to control
> os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'site1.settings')
>
> import django.core.handlers.wsgi
> application = django.core.handlers.wsgi.WSGIHandler()
>
> *site2 (site2/apache/django.wsgi)*
>
> import os, sys
> sys.path.append('/path/to/django/www/site2')
>
> # Quick fix, but not great
> # os.environ['DJANGO_SETTINGS_MODULE'] = 'site2.settings'
>
> # Original setting - use Apache mod_wsgi settings to control
> os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'site2.settings')
>
> import django.core.handlers.wsgi
> application = django.core.handlers.wsgi.WSGIHandler()
>
>
> Interestingly, when I deploy these files and restart Apache I only get 
> relevant output in the custom error log for site1 
> (in /path/to/django-8787-error_log) (Note also that this shows a complete 
> shutdown and startup series of notices):
>
> [Wed Feb 06 11:42:38 2013] [info] mod_wsgi (pid=18991): Shutdown 

Re: Any good books for learning django?

2013-02-07 Thread frocco
Thanks for the recommend. I just purchased it.

On Thursday, February 7, 2013 1:10:01 PM UTC-5, Mayukh Mukherjee wrote:
>
> I'd recommend two scoops of django.
> It's a little more intermediate level but it's a gem.
>
> Sent from my iPhone
>
> On Feb 7, 2013, at 12:49, frocco  wrote:
>
> Hello,
> Most of what I find are dated, 2008,2009.
> Are these still good for learning django 1.4?
>
> Which books do you recommend?
>
> 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...@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.
>  
>  
>
>

-- 
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: How to create a Django Group in case of multiple databases.

2013-02-07 Thread Tom Evans
On Thu, Feb 7, 2013 at 12:16 PM, laxglx  wrote:
>
> Hello Everybody,
>
> I'm going to create a Group using Django Group.
>
> I have two databases one is "master" and another is "slave"
> In master I created a user and group as usual.
>
> And in slave database I tried like this:
>
>
 Group.objects.db_manager('slave').create(name="grp1")
>
> This returned an error :
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python2.6/site-packages/django/db/models/manager.py", line
> 138, in create
> return self.get_query_set().create(**kwargs)
>   File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line
> 358, in create
> obj.save(force_insert=True, using=self.db)
> TypeError: save() got an unexpected keyword argument 'force_insert'

Have you trimmed this traceback?

>
> I also tried as follows, but got error :
>
 g = Group()
 g.name = "grp1"
 g.save(using='slave')
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: save() got an unexpected keyword argument 'using'
>

It looks like you have overwritten the save() method on the model you
are trying to save, and have not given it a method signature capable
of accepting the necessary arguments that save() is expected to
handle.

I say 'looks like', since I think you have obliterated the parts of
the traceback that would tell me…

save() takes many arguments. If you are not specifying any additional
arguments for your save() method, then it should look like so:

def save(self, *args, **kwargs):

This protects you from having to change the method if more arguments
are added in later versions of django, eg when the 'using' argument
was added in 1.2.

As usual, the docs have canonical instructions on how to override
model methods like save():

https://docs.djangoproject.com/en/1.4/topics/db/models/#overriding-model-methods

Cheers

Tom

-- 
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: Any good books for learning django?

2013-02-07 Thread Tom Evans
On Thu, Feb 7, 2013 at 5:49 PM, frocco  wrote:
> Hello,
> Most of what I find are dated, 2008,2009.
> Are these still good for learning django 1.4?
>
> Which books do you recommend?
>
> Thanks

An often overlooked resource is the django documentation itself. The
index page is arranged in complexity from least to most. If you are an
experienced web developer but new to django, just reading the topics
directly linked from the index will give you a good understanding of
what features django has, and where the documentation for a topic can
(roughly) be found.

As an added bonus, the docs are never out of date.

If you are new to both python and django, then a book on python itself
will probably be very useful also.

Cheers

Tom

-- 
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: Any good books for learning django?

2013-02-07 Thread Mayukh Mukherjee

I'd recommend two scoops of django.
It's a little more intermediate level but it's a gem.

Sent from my iPhone

On Feb 7, 2013, at 12:49, frocco  wrote:


Hello,
Most of what I find are dated, 2008,2009.
Are these still good for learning django 1.4?

Which books do you recommend?

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.




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




Any good books for learning django?

2013-02-07 Thread frocco
Hello,
Most of what I find are dated, 2008,2009.
Are these still good for learning django 1.4?

Which books do you recommend?

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.




Re: Formsets and auto_id's

2013-02-07 Thread David
I've kinda managed to achieve what I want but I can't help but think it's a 
bit of a fudge:



Especially this part: form.id.html_name

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




Formsets and auto_id's

2013-02-07 Thread David
Hi

I have a formset. Each form will only contain a checkbox. This checkbox 
needs to indicate which PK the form applies to.

The idea is that a user can scroll through this formset. Check which 
records they wish to delete and then remove them through a delete view.

auto_id's always seem to show as hidden fields and nothing I have tried 
changes this. Also how I can make sure that the checkbox value is the 
auto_id?

Thanks for any assistance.

-- 
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: No module named models again

2013-02-07 Thread Kelly Nicholes
Yeah, for things like forms.py and views.py, it's best to use relative 
imports for the models.py within the same app.

from .models import Object1


On Wednesday, February 6, 2013 7:22:19 PM UTC-7, frocco wrote:
>
> I found the answer.
> in my app directory called checkout, I also have a checkout.py file.
> from checkout.models import Order in views.py had to be changed to from 
> models import Order
>
> On Wednesday, February 6, 2013 3:02:57 PM UTC-5, Brad Pitcher wrote:
>>
>> On Wed, 2013-02-06 at 11:49 -0800, frocco wrote: 
>> > Line 22 does not make any sense to me as to why it is failing. 
>> > If I remove receipt, it runs fine 
>>
>> It can be surprising sometimes what code can cause other code to get 
>> imported and run. My guess is, in trying to find your url route there, 
>> Django looks through ntw.urls. When it sees 'receipts' it imports 
>> ntw.checkout.views to see if that view is there. Suffice it to say, 
>> Django is trying to run the code in ntw\checkout\views.py and it would 
>> be a good idea to make it work. 
>>
>>

-- 
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: post_save signal getting called twice !

2013-02-07 Thread Tom Evans
On Thu, Feb 7, 2013 at 1:54 PM, vijay shanker  wrote:
> Hi
> I am using django version 1.4.3
> I am using two signals in my models.py
> one is m2m_changed, so i can have a counter field (numcounter) of number of
> m2m fields attached, and another is post_save so i can decide whether to
> have a OneToOneField (cartrule, is to be applied only if there are more than
> 2 fields) or not.
> my models.py is:
>
> class CartItem(models.Model):
> content_type= models.ForeignKey(ContentType)
> object_id   = models.PositiveIntegerField()
> content_object  = generic.GenericForeignKey('
> content_type','object_id')
> quantity= models.PositiveIntegerField(default=0)
> is_abandoned= models.BooleanField(default=False)
> created_at  = models.DateTimeField(auto_now_add=True)
> update_at   = models.DateTimeField(auto_now=True)
> def __str__(self):
> return self.content_object.name
>
> class CartRule(models.Model):
> ##some field
> pass
>
> class Cart(models.Model):
> cart_id = models.CharField(max_length=50, null=False)
> customer= models.ForeignKey(Customer,null=True,blank=True)
> cartitems   = models.ManyToManyField(CartItem,null=True)
> created_at  = models.DateTimeField(auto_now_add=True)
> update_at   = models.DateTimeField(auto_now=True)
> cartrule   =
> models.OneToOneField(crapclass,null=True,blank=True)
> num_cartitem= models.IntegerField()
> def __str__(self):
> return self.cart_id
>
> @receiver(post_save, sender=Cart)
> def apply_condition(sender,instance,created,raw,using,*args,**kwargs):
> # i want to decide here if num_cartitem is greater than 2 its ok to have
> a cartrule
> pass
>
> @receiver(m2m_changed)
> def save_cartitem_counter(sender, instance, signal,*args, **kwargs):
> if kwargs['action'] == 'post_add':
> instance.num_cartitem = instance.cartitems.all().count()
> instance.save()
>
> the issue is apply_condition gets called twice, with similar value of args,
> first with older value of m2m (cartitem) field in Cart, the other time with
> the values i intended to save
> I looked into older post but still could not figure out the whys.How should
> i go about this ?
>

When you save a Cart instance, the post_save signal is triggered.
If the M2M relationship is changed as well, then the m2m_changed
signal is triggered. Your handler for this then re-saves the Cart
instance after denormalising data, which triggers the post save signal
for a second time.
You should probably connect the M2M receiver to a specific sender too,
currently it will fire whenever any M2M on any model is changed.

Keeping denormalized data like that is a pain, could you do without
it, and re-calculate it where necessary?

Alternatively, you could use a named intermediary M2M relationship:

https://docs.djangoproject.com/en/1.4/topics/db/models/#intermediary-manytomany

and connect signals on post_create and post_delete to the intermediary
model, updating the Cart as necessary.

This is a little more logical, since you wish to denormalise the data
whenever an item is added to or removed from a cart, ie whenever a row
is added or deleted to the intermediate table. Naming the relationship
allows you to connect the signals to the right place.

Cheers

Tom

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




post_save signal getting called twice !

2013-02-07 Thread vijay shanker
Hi
I am using django version 1.4.3
I am using two signals in my models.py
one is m2m_changed, so i can have a counter field (numcounter) of number of 
m2m fields attached, and another is post_save so i can decide whether to 
have a OneToOneField (cartrule, is to be applied only if there are more 
than 2 fields) or not.
my models.py is:

class CartItem(models.Model):
content_type= models.ForeignKey(ContentType)
object_id   = models.PositiveIntegerField()
content_object  = generic.GenericForeignKey('
content_type','object_id')
quantity= models.PositiveIntegerField(default=0)
is_abandoned= models.BooleanField(default=False)
created_at  = models.DateTimeField(auto_now_add=True)
update_at   = models.DateTimeField(auto_now=True)
def __str__(self):
return self.content_object.name

class CartRule(models.Model):
##some field
pass

class Cart(models.Model):
cart_id = models.CharField(max_length=50, null=False)
customer= models.ForeignKey(Customer,null=True,blank=True)
cartitems   = models.ManyToManyField(CartItem,null=True)
created_at  = models.DateTimeField(auto_now_add=True)
update_at   = models.DateTimeField(auto_now=True)
cartrule   = 
models.OneToOneField(crapclass,null=True,blank=True)
num_cartitem= models.IntegerField()
def __str__(self):
return self.cart_id
 
@receiver(post_save, sender=Cart)
def apply_condition(sender,instance,created,raw,using,*args,**kwargs):
# i want to decide here if num_cartitem is greater than 2 its ok to 
have a cartrule
pass

@receiver(m2m_changed)
def save_cartitem_counter(sender, instance, signal,*args, **kwargs):
if kwargs['action'] == 'post_add':
instance.num_cartitem = instance.cartitems.all().count()
instance.save()

the issue is apply_condition gets called twice, with similar value of args, 
first with older value of m2m (cartitem) field in Cart, the other time with 
the values i intended to save
I looked into older post but still could not figure out the whys.How should 
i go about this ?

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




post_save signal handler gets called twice !

2013-02-07 Thread vijay shanker
Hi
I am using django version 1.4.3
I am using two signals in my models.py
one is m2m_changed, so i can have a counter field (numcounter) of number of 
m2m fields attached, and another is post_save so i can decide whether to 
have a OneToOneField (cartrule, is to be applied only if there are more 
than 2 fields) or not.
my models.py is:

class CartItem(models.Model):
content_type= models.ForeignKey(ContentType)
object_id   = models.PositiveIntegerField()
content_object  = generic.GenericForeignKey('content_type','object_id')
quantity= models.PositiveIntegerField(default=0)
is_abandoned= models.BooleanField(default=False)
created_at  = models.DateTimeField(auto_now_add=True)
update_at   = models.DateTimeField(auto_now=True)
def __str__(self):
return self.content_object.name

class CartRule(models.Model):
##some field
pass

class Cart(models.Model):
cart_id = models.CharField(max_length=50, null=False)
customer= models.ForeignKey(Customer,null=True,blank=True)
cartitems   = models.ManyToManyField(CartItem,null=True)
created_at  = models.DateTimeField(auto_now_add=True)
update_at   = models.DateTimeField(auto_now=True)
cartrule   = 
models.OneToOneField(crapclass,null=True,blank=True)
num_cartitem= models.IntegerField()
def __str__(self):
return self.cart_id
 
@receiver(post_save, sender=Cart)
def apply_condition(sender,instance,created,raw,using,*args,**kwargs):
# i want to decide here if num_cartitem is greater than 2 its ok to 
have a cartrule
pass

@receiver(m2m_changed)
def save_cartitem_counter(sender, instance, signal,*args, **kwargs):
if kwargs['action'] == 'post_add':
instance.num_cartitem = instance.cartitems.all().count()
instance.save()

the issue is apply_condition gets called twice, with similar value of args, 
first with older value of m2m (cartitem) field in Cart.
I looked into older post but still could not figure out the whys. 

-- 
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 any way to apply a constraint on ForeignKey/OneToOneField being attached to any model based on some condition ?

2013-02-07 Thread Huu Da Tran
You could overwrite the save() method... or if you are populating from a 
form, overwrite the clean() method.

On Thursday, February 7, 2013 3:23:54 AM UTC-5, vijay shanker wrote:
>
> Hi
> I have these two models Cart and CartItem,
>
> class Cart(models.Model):
> cart_id = models.CharField(max_length=
> 50, null=False)
> customer= models.ForeignKey(Customer,null=True,blank=True)
> cartitems   = models.ManyToManyField(CartItem,null=True)
> applied_rule= 
> models.OneToOneField(CartRule,null=True,blank=True)
> 
>
> class CartItem(models.Model):
> content_type= models.ForeignKey(ContentType)
> object_id   = models.PositiveIntegerField()
> content_object  = generic.GenericForeignKey('content_type','object_id')
> quantity= models.PositiveIntegerField(default=0)
> is_abandoned= models.BooleanField(default=False)
> def __str__(self):
> return self.cart_id
>
> the rules to be applied only when there are more than two items in 
> shoppingcart, i.e i am looking for a way to attach a rule to cart only if 
> there are more than two items in cart (cartitems m2m field should have more 
> than two objects in it).
> How should i go about 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+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: Update / collectstatic / loadfixtures automation

2013-02-07 Thread Huu Da Tran
On Sunday, February 3, 2013 11:17:15 AM UTC-5, Thiago wrote:

> Yeah, it worked =)
> I tryed --noinput before but the behavior is a little different.
> Thanks!
>

In what sense is the --noinput different?

Also, I would suggest you split your script into two...

restart.sh that would contain all local stuffs:  source virtualenv, down to 
your restart.
deploy.sh that would ssh to host, call svn update, then call restart.sh

In this setup, you will be able to call restart.sh locally (assuming you 
have the same file structure as your prod).

-- 
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 ForeignKey versus ManyToManyField

2013-02-07 Thread Huu Da Tran
On Wednesday, February 6, 2013 1:39:30 AM UTC-5, vijay shanker wrote:

> I have two models, a Customer model and a WishListItem model (which stores 
> products). I have option of either having a ManyToManyField in Customer to 
> WishListItem, or I can have a customer ForeignKey to customer for each 
> WishListItem.
> Which one will be more efficient ? 
>

The most efficient is the one that gets the job done. The unclear question 
would be: what job are you trying to do. What is the business logic behind 
the model?

 1. The store has one toaster left. Two customers wants to fight to death 
for that toaster. ForeignKey (only one customer survives and gets it).
 2. The store sells toasters.  Two customers want to get one in turn. m2m 
(you don't duplicate the WishListItem)
 3. The store auctions two toasters. Two customers wants to get one. m2m 
with an intermediate table that could contain the bid price (you don't 
duplicate the WishListItem)
 4. The store is Santa Claus. Two well behaving children wish for a toaster 
(weird children). There is not necessarily an exact match between the two 
toasters. ForeignKey.
 5. etc...

-- 
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: Need guidance on static website conversion to Django

2013-02-07 Thread Steve Metivier
Thanks very much for the advice. I'm pretty sure that's the approach I'm 
going to take.
--steve

On Wednesday, February 6, 2013 3:59:59 PM UTC-7, Harry Houdini wrote:
>
>
> Maintaining that many static files has really got to suck, this is where 
> Django is going to help you a lot. First step for you because you are just 
> starting out it to play around with Django, build some base templates and 
> try extending them until you get your templates looking how you want. Then 
> go ahead and design the DB in a way that makes sense for making it easy to 
> edit and display your site content (and to add whatever features on top of 
> that you want- e.g the voting thing you wanted to add). 
>
> And overall think it would make more sense to start with a vanilla Django 
> install and get a feel for it before you jump to Mezzanine. I looked at 
> Mezzanine for a project and spent a few days messing around with it and 
> building up a site and I have to say that it adds a ton of functionality on 
> top of Django but has a learning curve when it comes to customization. They 
> modified django a lot compared to something like DjangoCMS I would say 
> (which is more of a plugin). Mezzanine is also pretty new and under very 
> active development (I follow their repo on Github, its pretty active) but 
> you can usually talk to people on their IRC channel about it if you get 
> stuck (its on freenode). 
>
> You might find you can build it fast enough with vanilla Django and a few 
> unobtrusive plugins and that you dont need the CMS stuff (django.admin does 
> a lot actually but has some limits).
>
>
>
> On Tuesday, February 5, 2013 1:37:06 PM UTC-5, Steve Metivier wrote:
>>
>>
>>- Project: Convert an essentially static HTML website and its 
>>attached WordPress blog, to Django, to improve on its currently slow load 
>>time, and to enable its functionality to be extended. (It’s currently 
>>implemented on a platform that I believe introduces significant overhead 
>> at 
>>runtime, and is very restrictive in extensibility. It’s on one of those 
>>“build your own website with no technical expertise” platforms.) 
>>I should note that I do have technical expertise, having been a 
>>professional developer in C for many years, and I now have a decent 
>> handle 
>>on HTML and CSS, but am a beginner with both Python and Django.
>>- The website is a famous quotes site. (It’s 
>>www.InspirationalSpark.com , if 
>>you want to take a look.) Each page focuses on a specific subject (which 
>>its URL indicates), and is comprised of some introductory text, including 
>>meta tags, followed by 12-20 famous quote entries, each made up of the 
>>quote itself, it’s author, and a short description. Finally, there are 
>>related page links at the bottom, and AdSense in several places. The 
>>navigation consists of topic links in the left column, and there is also 
>> a 
>>right column containing various elements that are shared on all pages.
>>- I envision each quote becoming a standalone object, so it can be 
>>shared socially and, eventually, rated/voted. I intend for each quote to 
>> be 
>>associated with a single topic page, for the most part.
>>- The purpose of the *blog* is to allow daily additions of new 
>>quotes, which are scheduled as a “quote of the day”, go out to a feed, 
>> and 
>>are posted to an associated Facebook page and to Twitter, and then listed 
>>on one of the topic pages. I don’t actually want the individual posts to 
>> be 
>>visible to the search engines, due to the thin content issue. They should 
>>only be visible within one of the topic pages, and on the home page.
>>- It’s critical that the page URLs remain unchanged, due to the 
>>number of inbound links that already exist, and current traffic (around 
>>10,000 views/day).
>>- I think what I’m looking for is a CMS, with a twist, to enable 
>>multiple objects per page. 
>>Here’s the long-term plan:
>>- Phase 1 – re-implement the website (separate from the blog), as is, 
>>in Django, to hopefully improve its currently poor load time. High 
>> priority 
>>is given to maintaining the current URLs completely, for SEO reasons, and 
>>to time to production launch.
>>- Phase 2 – migrate the current WordPress blog to Django.
>>- Phase 3 – add social media buttons to each quote on the page – for 
>>Facebook and twitter.
>>- Phase 4 – add user-created pages, where they can store and display 
>>their favorite quotes, with accounts and registration.
>>- Phase 5 – add voting on individual quotes within a page.
>>- Getting to phase 1 completion is a high priority, even if it means 
>>reworking components later to do so.
>>- The admin interface would need to provide for adding new quotes, 
>>and assigning them to topic pages, plus adding new topic pages. 

Re: Django superstars I should be following?

2013-02-07 Thread Amirouche


On Tuesday, February 5, 2013 9:51:17 PM UTC+1, Glyn Jackson wrote:
>
> I'm looking for suggestions on who to follow on twitter. 
> Who are the Django superstars, and the opinionated and guy/grils I should 
> be following?
>

Me  of course... 

Github following is interesting too but I keep that a secret of mine.

Good luck!

 

>
> :) Thanks in advance.
>
>
>

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




How to create a Django Group in case of multiple databases.

2013-02-07 Thread laxglx

Hello Everybody,

I'm going to create a Group using Django Group. 

I have two databases one is "master" and another is "slave" 
In master I created a user and group as usual. 

And in slave database I tried like this:


*>>> Group.objects.db_manager('slave').create(name="grp1")*

This returned an error : 

*Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/site-packages/django/db/models/manager.py", line 
138, in create
return self.get_query_set().create(**kwargs)
  File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 
358, in create
obj.save(force_insert=True, using=self.db)
TypeError: save() got an unexpected keyword argument 'force_insert'*

I also tried as follows, but got error :

*>>> g = Group()
>>> g.name = "grp1"
>>> g.save(using='slave')
Traceback (most recent call last):
  File "", line 1, in 
TypeError: save() got an unexpected keyword argument 'using'
*

Thanks in advance...


Laxmikant

-- 
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: m2m_changed signal can not distinguish between existing and newly added instances

2013-02-07 Thread vijay shanker
well .. odd .. replying my own post .. 
kwargs['action'] 

A string indicating the type of update that is done on the relation. This 
can be one of the following:
"pre_add"Sent *before* one or more objects are added to the relation.
"post_add"Sent *after* one or more objects are added to the relation.
"pre_remove"Sent *before* one or more objects are removed from the relation.
"post_remove"Sent *after* one or more objects are removed from the relation.
"pre_clear"Sent *before* the relation is cleared."post_clear"Sent *after*the 
relation is cleared. 


m2m_changed calls the handle_something function with different 
kwargs['action'] value which can help you differentiate between them.

On Friday, June 8, 2012 7:24:34 PM UTC+5:30, vijay shanker wrote:
>
> hi 
> i have this model  Client_Order 
> i want to do some manipulation each time a new pakg is added to this 
> field. 
> i used m2m_changed signal, but it cant distinguish between existing 
> instances attached and the newly added ones. 
> both post_add and pre_add show the same number of instances .. i.e if 
> a.b were attached and i added c instance to it .. both post_add and 
> pre_add give the same pk_set in kwargs 
>
> ACTV_STATUS = ( 
> ('Active','Active'), 
> ('Inactive','Inactive'), 
> ) 
>
> class Client_Order(models.Model): 
> order_name  = models.CharField(max_length=300) 
> order_desc  = models.TextField(verbose_name="Order 
> Description") 
> order_client= models.ForeignKey(Client_sda) 
> order_active_status = models.CharField(choices = ACTV_STATUS, 
> max_length=300) 
> order_pakages   = models.ManyToManyField(Pakage, 
> help_text="Please attach a maximum of 5 packages only. ") 
> discount= models.IntegerField(default=0) 
> total_amount= models.IntegerField() 
> order_booking_date  = models.DateField() 
> order_expiry_date   = models.DateField() 
>
> @receiver(m2m_changed) 
> def handle_something(sender, instance, signal,*args, **kwargs): 
> print kwargs 
> print 'pk_set->',kwargs['pk_set'] 
>
> how do i distinguish between newly added instances from previously 
> added ones ? 
>

-- 
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: Why doesn't form_valid() in FormView take a request argument?

2013-02-07 Thread Some Developer

On 06/02/13 23:00, Rainy wrote:

On Wednesday, February 6, 2013 3:09:39 PM UTC-5, Some Developer wrote:

Why doesn't the form_valid() (and for that matter the form_invalid())
method in the FormView generic class based view take a request
argument?

I've found that if you have a form which requires you to override the
form_valid() method because you need to do custom logic before you save
the model and you need to save the user ID of the person who posted the
form you need to also override the post() method in order to pass on
the
correct data by manually adding it to the post argument of the
form_valid() method by using request.user.

Am I missing something here? Is there any easier way to achieve what I
want to achieve?



How about using self.request attribute?  -rainy


Heh I don't know how I missed that. Thanks, that solves a couple of 
issues :).


I'm in the process of converting some old code to class based views and 
am still getting used to using them.


--
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 any way to apply a constraint on ForeignKey/OneToOneField being attached to any model based on some condition ?

2013-02-07 Thread vijay shanker
Hi
I have these two models Cart and CartItem,

class Cart(models.Model):
cart_id = models.CharField(max_length=
50, null=False)
customer= models.ForeignKey(Customer,null=True,blank=True)
cartitems   = models.ManyToManyField(CartItem,null=True)
applied_rule= 
models.OneToOneField(CartRule,null=True,blank=True)


class CartItem(models.Model):
content_type= models.ForeignKey(ContentType)
object_id   = models.PositiveIntegerField()
content_object  = generic.GenericForeignKey('content_type','object_id')
quantity= models.PositiveIntegerField(default=0)
is_abandoned= models.BooleanField(default=False)
def __str__(self):
return self.cart_id

the rules to be applied only when there are more than two items in 
shoppingcart, i.e i am looking for a way to attach a rule to cart only if 
there are more than two items in cart (cartitems m2m field should have more 
than two objects in it).
How should i go about 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+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 any way to stop foreignkey being attached to a django model depending upon some constraint ?

2013-02-07 Thread vijay shanker
Hi
I have these two models Cart and CartItem,

class Cart(models.Model):
cart_id = models.CharField(max_length=50, null=False)
customer= models.ForeignKey(Customer,null=True,blank=True)
cartitems   = models.ManyToManyField(CartItem,null=True)
applied_rule= 
models.OneToOneField(CartRule,null=True,blank=True)


class CartItem(models.Model):
content_type= models.ForeignKey(ContentType)
object_id   = models.PositiveIntegerField()
content_object  = generic.GenericForeignKey('content_type','object_id')
quantity= models.PositiveIntegerField(default=0)
is_abandoned= models.BooleanField(default=False)
def __str__(self):
return self.cart_id

the rules to be applied only when there are more than two items in 
shoppingcart, i.e i am looking for a way to attach a rule to cart only if 
there are more than two items in cart (cartitems m2m field should have more 
than two objects in it).
How should i go about 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+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.