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: 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: 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: Is it possible to have 1-to-Many and 1-to-1 relationships for one specific table?

2013-08-19 Thread Huu Da Tran
On Monday, August 19, 2013 3:03:25 PM UTC-4, Pepsodent Cola wrote:

> Is it possible to have 1-to-Many and 1-to-1 relationships for one specific 
> table?
> Because the database doesn't do what I wish for.
>

What is the intended goal?

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


Re: html templates and dynamic loading

2013-08-23 Thread Huu Da Tran
On Thursday, August 22, 2013 8:42:04 AM UTC-4, Bastien Amiel wrote:
 

> I need to update the chat when an event come but : 
>
> 1. 
> If I update my chat sub page, inputs are reset (seems logic since html 
> is recreated). 
>

You can always have some field that keep when the chat was started (in the 
session), and redisplay everything since that time.
 

> Then what would be the good / best method to update only the chat content 
> ? 
> (I have 2 ideas but they don't seems very Django'ic) 
>
> 2. 
> For now, I update the content every XX ms with a periodic request client 
> side. 
> Would it be possible / preferable to have a push from server when new 
> data comes or is there a better way to update this kind of content ?


Trying to hack django to get server push would be hell (look into tornado). 
If you really need server push, you may need to look into other 
technologies, like nodejs.

Using the periodic request client-side is what is mostly done.

 
Hope this helps.

HD.

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


Re: Need Advise on the best way to track how much time a user is logged in.....

2013-08-23 Thread Huu Da Tran
On Thursday, August 22, 2013 3:09:45 PM UTC-4, 7equiv...@gmail.com wrote:

> My users will not be able to logout by closing a browser because they have 
> no such interaction with the system. They will be passing an RFID tag over 
> a reader to unlock the door and clock in and a python script will handle 
> the loging in and out. So if I can get the logout to time stamp a database 
> entry I'll be good.
>

Am I just missing your point or you are actually defining a website with a 
login function and a logout function? If so, in the view for login, just 
call

user.userlogin_set.create(timestamp=datetime.datetime.utcnow())

and in the logout view, just call

user.userlogout_set.create(timestamp=datetime.datetime.utcnow())


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