Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #MODELO
- class District(models.Model):
- """
- Ahora son llamados distritos, no ciudades
- """
- name = models.CharField(
- verbose_name=_("Name"),
- max_length=30,
- help_text=_("Name"),
- blank=False,
- null=False
- )
- ref = models.CharField(
- verbose_name=_("District code"),
- max_length=5,
- help_text=_("District code")
- )
- municipality = models.ForeignKey(
- Municipality,
- on_delete=models.CASCADE,
- null=False, blank=False,
- help_text=_("Municipality that belongs"),
- verbose_name=_("Municipality")
- )
- lat = models.FloatField(
- verbose_name=_("Latitude"),
- help_text=_("Latitude"),
- default=0.0,
- )
- lng = models.FloatField(
- verbose_name=_("Longitude"),
- help_text=_("Longitude"),
- default=0.0
- )
- area_poly = models.MultiPolygonField(
- verbose_name=_("Map area"),
- help_text=_("Map area"),
- blank=True,
- null=True
- )
- def __str__(self):
- return "{}".format(self.name)
- class Meta:
- verbose_name = _('District')
- verbose_name_plural = _('Districts')
- #FORM PARA USAR EL JS CUSTOM
- from leaflet.admin import LeafletGeoAdmin
- class DistrictForm(LeafletGeoAdmin):
- class Media:
- js = ('/static/js/district.js',)
- #JS CARGADO CORRECTAMENTE
- (function($) {
- var lat = $("input[name='lat']").attr("value");
- var lng = $("input[name='lng']").attr("value");
- $("#id_area_poly-map").on('map:loadfield', function (e) {
- console.log(e.field, e.fieldid);
- });
- })(django.jQuery);
- #URL EN SETTINGS
- admin.site.register(District, DistrictForm)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement