As stated I have a couple of tables set up like so connected by locaciones
nombre = models.CharField(‘Nombre’, max_length=250)
direccion = models.CharField(‘Direccion’, max_length=250)
mapa = models.URLField
class Evento (models.Model):
artista = models.CharField(‘Artista’, max_length=250, blank=True, null=True)
nombre = models.CharField(‘Evento’, max_length=250, blank=True, null=True)
fechayhora = models.DateTimeField(‘Fecha’, max_length=50, blank=True, null=True)
locacion = models.ForeignKey(Locaciones, blank=True, null=True, on_delete=models.CASCADE)
pais = models.CharField(‘Pais’, max_length=50, blank=True, null=True)
director = models.CharField(‘Director’, max_length=50, blank=True, null=True)
disciplina = models.CharField(‘Disciplina’, max_length=50, blank=True, null=True)
duracion = models.CharField(‘Duracion’, max_length=50, blank=True, null=True)
the problem is that in the admin area the first class shows up with another s. Instead of being Locaciones reads Locacioness and when I try and add a location it wont show the actual name given, just shows Locaciones object (3) even when selecting from the drop down menu on the Eventos table, furthermore I tried to solve this by changing the class name from Locacion to Locaciones because I was having the same issue where the admin area adds an s to the class name. This is the first app I code in any capacity so Im out of ideas, a glitch maybe?
This isn’t a problem. This is defined behavior on the model class.
See Model Meta options | Django documentation | Django
and The Django admin site | Django documentation | Django
Again, this is defined behavior. See Form fields | Django documentation | Django among other references.
Hey thanks for the quick reply, I’m following a tutorial and it looks to me I’ve been writing the exact same models and his tables don’t behave like that, on the +s thing nor the form fields, so I’m confused, is this a different version issue or am I missing something on his tutorial?
There’s no way I can comment without seeing the tutorial.
OK, thanks for your time.
I don’t know how deeply you want to look into this, but on the surface level…you can re-define the plural name with verbose_name_plural=“newname” (ie. look at link posted by Ken), add it to your model as the last option in the list of options/arguments you apply to the model.
Hey, thanks for taking the time to reply, I was trying to figure where to add the verbose option to my model, I really don’t mind the name, but would like to figure out why would that be necessary as an expected behavior, actually the real issue is that the actual entries are shown as objects on the admin page, so going through the documentation I’m wondering if I need to use the
method so I get the name not the object 1 string that is being returned; and pardon my ignorance but such model should be placed on the models.py file and should I be importing any file in particular up top?
Does this sound like it would work?
The admin is not the only place where the pluralized name is available. So yes, the definition of the pluralized name goes in the
Meta class of the model. You add an entry in that class for
Because it’s the defined and designed behavior of how Django works.
Regarding your other question - the links provided to the documentation explain that the select list entries are created by the output of the
__str__ method on the model class. Overriding that method on the related class is the easiest way to change the representation of that class in the admin.
It is entirely to do with how you define the field object name. You don’t need to import anything special. If you want a code example can make it, it’s been said: define
def __str__ to return exactly what you want, so it wont be returning object(3) or something like that. When you omit
__str__ that’s what happens.
hi Ken, the necessary expected behavior question was more on the practical ways that may be useful or is it convention to do it, kinda way, wasnt trying to be snotty, I appreciate you taking the time to answer noobs like me, Ill just take some time to work through it, thank you for your replies!
Aight I think I got it, just tweak the return statement to add some constraints? The example was very helpful, thank you for your time