send a pk of an object to a createview as fk of the other object



class Mascota(models.Model):
    nombre = models.CharField(max_length=25)
    raza = models.ForeignKey(Raza, null=False, blank=False, on_delete = models.CASCADE)
    color = models.ForeignKey(ColorMascota, null=False, blank=False, on_delete=models.CASCADE)
    genero = models.ForeignKey(GeneroMascota, null=False, blank=False, on_delete=models.CASCADE)
    fecha_nac = models.DateField(null=True,blank=True)
    marca_visible = models.CharField(max_length=75, null=True, blank=True)
    alergias = models.CharField(max_length=50, null=True, blank=True)
    peso = models.IntegerField(null=True, blank=True)
    registro = models.CharField(max_length=50, null=True, blank=True)
    observaciones = models.TextField(null=True, blank=True)
    cliente = models.ForeignKey(Cliente, null=False,blank=False, on_delete=models.CASCADE)

class FichaServicio(models.Model):
    mascota = models.ForeignKey(Mascota, null=False, blank=False, on_delete=models.CASCADE)
    fecha_in = models.DateField(null=False, blank=False)
    fecha_out = models.DateField(null=True, blank=True)
    servicio = models.ManyToManyField(TipoServicio, null=False, blank=True)
    peso = models.IntegerField(null=True, blank=True)
    observaciones = models.TextField(null=True,blank=True)


class FichaVacunaList(ListView):
    model = FichaVacuna
    template_name = 'vacuna/fichavacuna_list.html'
class FichaVacuna(CreateView):
    model = FichaVacuna
    form_class = FichaVacunaForm
    template_name = 'vacuna/fichavacuna_form.html'
    success_url = '/mascota/vaclist'


url(r'^vaclist$', FichaVacunaList.as_view(), name='fichavacuna_list'),
url(r'^vaccreate$', FichaVacuna.as_view(), name='fichavacuna_create'),

I want to send the pet id from MascotaList to create a new vaccination record but converting that id to fk of the Vaccine tab. My question is if you can and how to do it since I am starting

asked by Draco1285 06.12.2018 в 04:54

0 answers