I installed a third party app which has basically 5 fields: id, name, state, geocode, geometry.
I created a new app which I need to import only the values from the 'name' field from the other model.
So I basically did this:
from django.db import models
from django.contrib.auth.models import User
from django.contrib.gis.geos import Point
from brasil_municipios.models import Municipio #which is the third party app
class Escritorio(models.Model):
nomeescritiorio = models.CharField(max_length=255)
cidade = models.OneToOneField(Municipio.objects.values_list('name').order_by('name')[0:10], on_delete=models.PROTECT, null=True)
And got this error:
AssertionError: OneToOneField(<QuerySet [('ABADIA DE GOIÁS',), ('ABADIA DOS DOURADOS',), ('ABADIÂNIA',), ('ABAETETUBA',), ('ABAETÉ',), ('ABAIARA',), ('ABARÉ',), ('ABATIÁ',), ('ABAÍRA',), ('ABDON BATISTA',)]>) is invalid. First parameter to ForeignKey must be either a model, a model name, or the string 'self'
I already tried others ways to solve the issue, using filter(), get() and etc, but all get the same error in all of them.
Any tip will be really helpful. Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire