How to get a subset of %s_%s_changelist

31 Views Asked by At

The following code works correctly:

I have the models(.../models.py):

Water point

class Pagua(models.Model):
    idpg = models.CharField(primary_key=True, max_length=255,)
    observaciones = 
models.CharField(verbose_name='Observaciones',max_length=200,blank=True,null=True)

    class Meta:
        managed = False
        db_table = 'pagua'
        verbose_name = "Punto de agua"
        verbose_name_plural = "Puntos de agua"
    def __str__(self):
        return str(self.idpg)

Surface water point (inherits from class Pagua)

class Pasup(Pagua):
    num_p = models.CharField(verbose_name='Número punto',max_length=50)
    tipo_pg = models.CharField(verbose_name='Tipo',max_length=200, 
default='Superficial')
    denominacion = models.CharField(verbose_name='Denominación',max_length=200, blank=True, null=True)
    cota = models.FloatField(verbose_name='Cota [m.s.n.m]',blank=True, null=True)
    latitud = models.FloatField(verbose_name='Latitud [decimal]',blank=True, null=True)
    longitud = models.FloatField(verbose_name='Longitud [decimal]',blank=True, null=True)
    geom = models.PointField(blank=True, null=True,srid=4326)

    class Meta:
        managed = False
        db_table = 'pasup'
        verbose_name = "Punto de agua superficial"
        verbose_name_plural = "Puntos de agua superficiales"
    
    def __str__(self):
        return str(self.pagua_ptr_id)
    

Chemical data:

class Dquimicos(models.Model):
    analisisnum = models.IntegerField(primary_key=True)
    idpg = models.ForeignKey('registrar_p.Pagua', models.CASCADE, db_column='idpg')

    tipoanalisis = models.CharField(verbose_name='Tipo análisis',max_length=200, blank=True, null=True)
    fecha = models.DateField(verbose_name='Fecha',blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'dquimicos_0'
        verbose_name = "Datos químicos (encabezado)"
        verbose_name_plural = "Datos químicos (encabezados)"


    def __str__(self):
        return str(self.analisisnum)
    
    

The views (.../views.py):

This view shows the list of changes with ALL Chemical records:

def verdquimicos(request):

    myapplabel = Dquimicos._meta.app_label
    mymodelname = Dquimicos._meta.model_name
    infodata = myapplabel+'_'+mymodelname

    return HttpResponseRedirect(reverse("admin:%s_changelist" % infodata))

This view receives the pk parameter and displays the CHANGE page for the water point whose idpg = pk def verpagua(request,pk):

    myapplabel = Pagua._meta.app_label
    mymodelname = Pagua._meta.model_name
    infodata = myapplabel+'_'+mymodelname

    return HttpResponseRedirect(reverse("admin:%s_change" % (infodata),None,(pk,),))

The urls (urls.py):

urlpatterns = [

path('dquimicos/',verdquimicos, name='verdquimicos'),
path('pagua/<str:pk>',verpagua, name='verpagua'),

]

Problems:

One: I need the list of changes page to display only records with chemical data from a specific water point whose id is passed by parameter.

Two: I need the list of changes page to display only records with specific water point whose id is passed by parameter.

For example This does not work:

def verpagua(request,pk):

    myapplabel = Pagua._meta.app_label
    mymodelname = Pagua._meta.model_name
    infodata = myapplabel+'_'+mymodelname

    return HttpResponseRedirect(reverse("admin:%s_changelist" % (infodata),None,(pk,),)) }
0

There are 0 best solutions below