I am discovery Django and after following the tuto from the (Django web site → Documentation → First Steps → Turorials) , I am trying to build my app.
I have a database with about 1 million of measures but my goal is not to show all yet.
My database has about 10 tables and I am using a lot of JOIN. I developped a PHP/MySQL script which works fine but I would like to migrate my work with Django/Python.
My project has some Fields. Ia field, there are actived and inactived stations and each station has sensors.
I crated a view here
(Sadly, as I am a new user, I can only add 2 links)
and the template fields.html print all the field.
- duvernay (46.183534,6.004783) (ocalhost:8080/console/5/stations)
- Perrières (46.217744,6.013987) (localhost:8080/console/4/stations)
- boigies (46.184610,6.008253) (localhost:8080/console/3/stations)
- hutins (46.186090,5.997505) (localhost:8080/console/2/stations)
- printaniere (46.173291,6.003578) (localhost:8080/console/1/stations)
Here is the model
When I click on the first field, the view stations, show me ALL stations
class StationsView(generic.ListView): #model = Stations context_object_name = 'stations_list' template_name = 'console/stations.html' def get_queryset(self): """Return the last five published station.""" return Stations.objects.order_by('-station_created')[:30]
Here is the stations model
class Stations(models.Model): id_station = models.AutoField(primary_key=True) fields_id_field = models.ForeignKey(Fields, models.DO_NOTHING, db_column='fields_id_field') stations_types_id_stations_type = models.IntegerField() station_name = models.CharField(max_length=20) station_longname = models.CharField(max_length=45, blank=True, null=True) station_active = models.IntegerField() station_archive = models.IntegerField() station_lat = models.FloatField(blank=True, null=True) station_lng = models.FloatField(blank=True, null=True) station_alt = models.DecimalField(max_digits=6, decimal_places=2, blank=True, null=True) installed = models.DateTimeField() station_description = models.TextField(blank=True, null=True) ttn_app_id = models.CharField(max_length=20) ttn_dev_id = models.CharField(max_length=20) ttn_hardware_serial = models.CharField(max_length=20) station_created = models.DateTimeField() station_order = models.IntegerField() map = models.IntegerField() class Meta: managed = False db_table = 'stations'
I would like to know, how can I filter the station for the selected field, and how can I hidden the inactivate station.
Other question will come, but it would be nice, I understand how can I first filter my queries