Saturday, October 9, 2010

how to prevent different instances with same state

I have a model called Tracker that has a User and a url .I need User-
url combination to be unique.So I made

classTracker(models.Model):
url=models.URLField()
owner=models.ForeignKey(User)
class Meta:
unique_together = (("owner", "url"),)

Now,I need to create a TrackingUtility that takes a Tracker object and
does some processing using the data at the url.

class TrackingUtility:
def __init__(self,tracker):
self.url=self.tracker.url
self.owner=self.tracker.owner
def do_something(self):
....

I need to make sure that only one instance of TrackingUtility with the
given tracker object exists.I mean if a client calls ,

user1=User.objects.get(id=1)
user2=User.objects.get(id=2)

tr1=Tracker(user1,'url1')

trackutil1=TrackingUtility(tr1)
trackutil2=TrackingUtility(tr1)

then there should only be one TrackingUtil object with Tracker of
user1 and 'url1' .How do I ensure this?

Any suggestions most welcome.
thanks,
harry

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate