Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Jan. 26, 2011 11:57:17

Jaroslav D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

forbid clones


Hi,

how can I forbid that clones of a certain type are stored by an admin?

Example: Suppose there are cars in the database and cars have as only
attribute a name. How can I prevent that two cars that have the same
name are stored?

Jaroslav

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

Offline

#2 Jan. 26, 2011 11:58:49

Tom E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

forbid clones


On Wed, Jan 26, 2011 at 11:57 AM, Jaroslav Dobrek
<jaroslav.dob...@gmail.com> wrote:
> Hi,
>
> how can I forbid that clones of a certain type are stored by an admin?
>
> Example: Suppose there are cars in the database and cars have as only
> attribute a name. How can I prevent that two cars that have the same
> name are stored?
>
> Jaroslav
>http://docs.djangoproject.com/en/1.2/ref/models/fields/#uniqueHTH

Tom

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

Offline

#3 Jan. 26, 2011 12:01:49

Jaroslav D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

forbid clones


>http://docs.djangoproject.com/en/1.2/ref/models/fields/#unique>

Wow, thanks. In this group answers almost come before one is able to
submit the posting.

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

Offline

#4 Jan. 26, 2011 12:26:37

Jaroslav D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

forbid clones


>
>http://docs.djangoproject.com/en/1.2/ref/models/fields/#uniqueAlthough this does help, it leaves one question open:

How can we forbid only such pairs of objects that have the same value
in all of their attributes.

Example:

This should be allowed:

car1: manufacturer = "foo", name = "bar"
car2: manufacturer = "foo", name = "baz"

This should not be allowed:

car1: manufacturer = "foo", name = "bar"
car2: manufacturer = "foo", name = "bar"


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

Offline

#5 Jan. 26, 2011 12:29:52

Chris M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

forbid clones


Have a look at unique_together:
Django | Model Meta options | Django documentationhttp://docs.djangoproject.com/en/dev/ref/models/options/Jump to unique_together‎: Options.unique_together¶. Sets of field names that,
... For convenience, unique_together can be a single list when dealing ...
docs.djangoproject.com/en/dev/ref/models/options/
Labeled Latest docs 1.0 docs All docs


-----Original Message-----
From: django-users@googlegroups.com On
Behalf Of Jaroslav Dobrek
Sent: 26 January 2011 14:26
To: Django users
Subject: Re: forbid clones

>
>http://docs.djangoproject.com/en/1.2/ref/models/fields/#uniqueAlthough this does help, it leaves one question open:

How can we forbid only such pairs of objects that have the same value
in all of their attributes.

Example:

This should be allowed:

car1: manufacturer = "foo", name = "bar"
car2: manufacturer = "foo", name = "baz"

This should not be allowed:

car1: manufacturer = "foo", name = "bar"
car2: manufacturer = "foo", name = "bar"


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

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

Offline

#6 Jan. 26, 2011 12:34:32

Adrian B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

forbid clones


On 26 Jan 2011, at 12:26, Jaroslav Dobrek wrote:

>>
>>http://docs.djangoproject.com/en/1.2/ref/models/fields/#unique> Example:
>
> This should be allowed:
>
> car1: manufacturer = "foo", name = "bar"
> car2: manufacturer = "foo", name = "baz"
>
> This should not be allowed:
>
> car1: manufacturer = "foo", name = "bar"
> car2: manufacturer = "foo", name = "bar"

Doesn't look to be directly possible from the Django's API; but I guess you
could,

class Car(models.Model):
manufacturer = models.CharField(max_length=127)
name = models.CharField(max_length=127)
manufacturer_name = models.CharField(max_length=256, unique=True)

def save(self, *args, **kwargs):
manufacturer_name = "%s_%s" % (self.manufacturer, self.name)
super(Charge, self).save(*args, **kwargs)

aid

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

Offline

#7 Jan. 26, 2011 12:36:19

Adrian B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

forbid clones


Please ignore this dumn-ass p
On 26 Jan 2011, at 12:34, Adrian Bool wrote:

>
> On 26 Jan 2011, at 12:26, Jaroslav Dobrek wrote:
>
>>>
>>>http://docs.djangoproject.com/en/1.2/ref/models/fields/#unique>> Example:
>>
>> This should be allowed:
>>
>> car1: manufacturer = "foo", name = "bar"
>> car2: manufacturer = "foo", name = "baz"
>>
>> This should not be allowed:
>>
>> car1: manufacturer = "foo", name = "bar"
>> car2: manufacturer = "foo", name = "bar"
>
> Doesn't look to be directly possible from the Django's API; but I guess you
> could,
>
> class Car(models.Model):
> manufacturer = models.CharField(max_length=127)
> name = models.CharField(max_length=127)
> manufacturer_name = models.CharField(max_length=256, unique=True)
>
> def save(self, *args, **kwargs):
> manufacturer_name = "%s_%s" % (self.manufacturer, self.name)
> super(Charge, self).save(*args, **kwargs)
>


Urgh. Please ignore this dis-information. Hat off to Chris for knowing what
he types.

aid


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

Offline

#8 Jan. 26, 2011 14:30:18

Jaroslav D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

forbid clones


On 26 Jan., 13:29, Chris Matthews <ch...@bbd.co.za> wrote:
> Have a look at unique_together:
> Django | Model Meta options | Django
> documentationhttp://docs.djangoproject.com/en/dev/ref/models/options/>
> Jump to unique_togetherý: Options.unique_together¶. Sets of field names that,
> ... For convenience, unique_together can be a single list when dealing ...

Great, thank you. That is exactly what I was looking for.

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

Offline

Board footer

Moderator control

Enjoy the 19th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support