Re: unique_together does not work in django 2.0

2018-01-19 Thread James Bennett
You've indented the 'Meta' declaration too much, and Python thinks it's
part of the '__str__()' method of your class.

Un-indent it one level.

On Thu, Jan 18, 2018 at 4:28 PM, FernandoJMM 
wrote:

> Hello,
> I have the following class:
>
> ==
> class Silo(models.Model):
> nave = models.ForeignKey(Nave, on_delete=models.CASCADE)
> codSil = models.CharField(
> 'Código Silo', db_index=True, max_length=2, default='01')
> notas = models.TextField(null=True, blank=True)
>
> def __str__(self):
> return "%s %s" % (self.nave, self.codSil)
>
> class Meta:
> order_with_respect_to = 'nave'
> unique_together = ('nave', 'codSil')
> 
>
> But the option unique_together does not work because duplicate values
> ​​exist in the SQLite database for nave and codSil.
>
> To solve it, I have to create the index nave + codSil by hand in the
> SQLite database ???
>
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/555b1903-b6f5-4af1-b7a2-a7921d1fdbac%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAL13Cg8xH9Js57oBD%2BvJNdxucrimyhvYV2-jYV3mcNLFiYVczw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: unique_together does not work in django 2.0

2018-01-19 Thread FernandoJMM

Hello, Problem solved. 
For it to work I have to put the META class between the silo class and the 
method. Thank you

El viernes, 19 de enero de 2018, 12:53:28 (UTC+1), Jason escribió:
>
> To be clear, you started with an empty database and the duplicate values 
> exist after adding 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d385d85a-c87f-4742-8c75-f430048f7554%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: unique_together does not work in django 2.0

2018-01-19 Thread Jason
To be clear, you started with an empty database and the duplicate values 
exist after adding 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/529e8c4d-bedb-40a4-ac42-c7ad42e5d6ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


unique_together does not work in django 2.0

2018-01-18 Thread FernandoJMM
Hello,
I have the following class:

==
class Silo(models.Model):
nave = models.ForeignKey(Nave, on_delete=models.CASCADE)
codSil = models.CharField(
'Código Silo', db_index=True, max_length=2, default='01')
notas = models.TextField(null=True, blank=True)

def __str__(self):
return "%s %s" % (self.nave, self.codSil)

class Meta:
order_with_respect_to = 'nave'
unique_together = ('nave', 'codSil')


But the option unique_together does not work because duplicate values 
​​exist in the SQLite database for nave and codSil.

To solve it, I have to create the index nave + codSil by hand in the SQLite 
database ???

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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/555b1903-b6f5-4af1-b7a2-a7921d1fdbac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.