0
votes

I'm trying to create a model that has 2 fields with the same related object (Call):

class Call(LogsMixin, models.Model):
    """Definición del modelo de Proveedor."""

    id = models.CharField("ID de la convocatoria", primary_key=True, null=False, default="", max_length=50)
    name = models.CharField("Nombre de convocatoria", null=False, default="", max_length=200)
    active = models.BooleanField("Activada", default=True)


class Consumption(LogsMixin, models.Model):
    """Definición del modelo de Consumos"""

    client = models.ForeignKey('authentication.Client', verbose_name=("Cliente"), null=True, default=None, on_delete=models.SET_DEFAULT)
    sap_price = models.DecimalField(("Precio de SAP"), max_digits=6, decimal_places=2, null=False, default=0)
    access_date = models.DateField("Fecha de acceso", auto_now=False, auto_now_add=False)
    call = models.ForeignKey(Call, verbose_name=("Convocatoria"), null=True, default=None, on_delete=models.SET_DEFAULT)
    accessible_calls = models.ManyToManyField(Call, verbose_name=("Convocatorias accesibles"))

When I try to make the migrations I receive the next error:

ERRORS: consumptions.Consumption.accessible_calls: (fields.E304) Reverse accessor for 'Consumption.accessible_calls' clashes with reverse accessor for 'Consumption.call'. HINT: Add or change a related_name argument to the definition for 'Consumption.accessible_calls' or 'Consumption.call'. consumptions.Consumption.call: (fields.E304) Reverse accessor for 'Consumption.call' clashes with reverse accessor for 'Consumption.accessible_calls'. HINT: Add or change a related_name argument to the definition for 'Consumption.call' or 'Consumption.accessible_calls'.

And yes, I read the HINT, but it's not what I need

I need this because I need the call that the client selected and the calls that he can choose

Does anyone have any clue?

1
HINT: Add or change a related_name argument to the definition for 'Consumption.accessible_calls' or 'Consumption.call'. consumptions.Consumption.calliklinac
Won't work, is not what I wantAngelQuesada
What do you mean it won't work, it is clear that you have two clashing related_namesiklinac

1 Answers

1
votes

You have two fields with same reverse related_name that are automatically constructed by Django as call_set

you should change one of them to unique value

accessible_calls = models.ManyToManyField(Call, verbose_name=("Convocatorias accesibles", related_name="my_related_name"))