Re: Problems with "Class Meta" and " __str__"

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Problems with "Class Meta" and " __str__"

Team Infinity
I think you moved to Django with no prior knowledge of Python.
Here is the fix for that
Screenshot from 2019-09-10 22-31-47.png

On Tue, Sep 10, 2019 at 10:15 PM Elmaco7 <[hidden email]> wrote:
Hello, I do these models but the Django admin page doesn't read the "class Meta" and " __str__".
This is the models.py document

from django.db import models

# Create your models here.


class Autore(models.Model):
    nome = models.CharField(max_length=50)
    cognome = models.CharField(max_length=50)
def __str__(self):
        return self.autore_text
class Meta:
    verbose_name_plural = "Autori"

class Genere(models.Model):
    descrizione = models.CharField(max_length=30)
def __str__(self):
        return self.genere_text
class Meta:
    verbose_name_plural = "Generi"

class Libro(models.Model):
    titolo = models.CharField(max_length=200)
    autore = models.ForeignKey(Autore, on_delete=models.CASCADE)
    genere = models.ForeignKey(Genere, on_delete=models.CASCADE)
def __str__(self):
        return self.libro_text
class Meta:
    verbose_name_plural = "Libri"


These are the results




Can someone help me?

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c1941b52-7d2b-4b09-8ead-fce630b73757%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMq-%2BzVWksT17yx90YYO2zHJG7qTuMoZTNWPLBq9GSFskRAGzg%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with "Class Meta" and " __str__"

HULUGESH B
def __str__(self):
        return self.name



On Tue, Sep 10, 2019, 8:30 PM Elmaco7 <[hidden email]> wrote:
Hello, I do these models but the Django admin page doesn't read the "class Meta" and " __str__".
This is the models.py document

from django.db import models

# Create your models here.


class Autore(models.Model):
    nome = models.CharField(max_length=50)
    cognome = models.CharField(max_length=50)
def __str__(self):
        return self.autore_text
class Meta:
    verbose_name_plural = "Autori"

class Genere(models.Model):
    descrizione = models.CharField(max_length=30)
def __str__(self):
        return self.genere_text
class Meta:
    verbose_name_plural = "Generi"

class Libro(models.Model):
    titolo = models.CharField(max_length=200)
    autore = models.ForeignKey(Autore, on_delete=models.CASCADE)
    genere = models.ForeignKey(Genere, on_delete=models.CASCADE)
def __str__(self):
        return self.libro_text
class Meta:
    verbose_name_plural = "Libri"


These are the results




Can someone help me?

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c1941b52-7d2b-4b09-8ead-fce630b73757%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKfjjGrMMEkg85LOVGhDeSes%3D4eMzoh%3DTn%2BwyS%2Bc5VxWMBMiPw%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with "Class Meta" and " __str__"

Amitesh Sahay
I guess you should define the Meta class just under the main class, ie.

class Autore(models.Model):
    nome = models.CharField(max_length=50)
    cognome = models.CharField(max_length=50)
    class Meta:
        verbose_name_plural = "Autori"




Regards,
Amitesh Sahay
91-750 797 8619


On Tuesday, 10 September, 2019, 11:50:20 pm IST, Doddahulugappa.B <[hidden email]> wrote:


def __str__(self):
        return self.name



On Tue, Sep 10, 2019, 8:30 PM Elmaco7 <[hidden email]> wrote:
Hello, I do these models but the Django admin page doesn't read the "class Meta" and " __str__".
This is the models.py document

from django.db import models

# Create your models here.


class Autore(models.Model):
    nome = models.CharField(max_length=50)
    cognome = models.CharField(max_length=50)
def __str__(self):
        return self.autore_text
class Meta:
    verbose_name_plural = "Autori"

class Genere(models.Model):
    descrizione = models.CharField(max_length=30)
def __str__(self):
        return self.genere_text
class Meta:
    verbose_name_plural = "Generi"

class Libro(models.Model):
    titolo = models.CharField(max_length=200)
    autore = models.ForeignKey(Autore, on_delete=models.CASCADE)
    genere = models.ForeignKey(Genere, on_delete=models.CASCADE)
def __str__(self):
        return self.libro_text
class Meta:
    verbose_name_plural = "Libri"


These are the results




Can someone help me?

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c1941b52-7d2b-4b09-8ead-fce630b73757%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKfjjGrMMEkg85LOVGhDeSes%3D4eMzoh%3DTn%2BwyS%2Bc5VxWMBMiPw%40mail.gmail.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1997993869.4201313.1568141384098%40mail.yahoo.com.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with "Class Meta" and " __str__"

Ezequias Rocha
In reply to this post by Team Infinity
In your base model write a function like this (if your description field is called 'name'):

    def __str__(self):
        return self.name

It works for me.
PS: Take care of python identation. I don't know if your tabulation is the same you paste here in forum but it placed wrongly could compromise your execution.

Good luck
Ezequias.

On Tuesday, September 10, 2019 at 1:30:28 PM UTC-3, Elmaco7 wrote:
Hello, I do these models but the Django admin page doesn't read the "class Meta" and " __str__".
This is the models.py document

from django.db import models

# Create your models here.


class Autore(models.Model):
    nome = models.CharField(max_length=50)
    cognome = models.CharField(max_length=50)
def __str__(self):
        return self.autore_text
class Meta:
    verbose_name_plural = "Autori"

class Genere(models.Model):
    descrizione = models.CharField(max_length=30)
def __str__(self):
        return self.genere_text
class Meta:
    verbose_name_plural = "Generi"

class Libro(models.Model):
    titolo = models.CharField(max_length=200)
    autore = models.ForeignKey(Autore, on_delete=models.CASCADE)
    genere = models.ForeignKey(Genere, on_delete=models.CASCADE)
def __str__(self):
        return self.libro_text
class Meta:
    verbose_name_plural = "Libri"


These are the results




Can someone help me?

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/131b9bda-ba3c-4ebc-8471-c1fdabb8f5e5%40googlegroups.com.