Advertisement
Guest User

Django admin form

a guest
Dec 11th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.72 KB | None | 0 0
  1. #MODELO
  2. class District(models.Model):
  3.     """
  4.        Ahora son llamados distritos, no ciudades
  5.    """
  6.     name = models.CharField(
  7.         verbose_name=_("Name"),
  8.         max_length=30,
  9.         help_text=_("Name"),
  10.         blank=False,
  11.         null=False
  12.     )
  13.     ref = models.CharField(
  14.         verbose_name=_("District code"),
  15.         max_length=5,
  16.         help_text=_("District code")
  17.     )
  18.     municipality = models.ForeignKey(
  19.         Municipality,
  20.         on_delete=models.CASCADE,
  21.         null=False, blank=False,
  22.         help_text=_("Municipality that belongs"),
  23.         verbose_name=_("Municipality")
  24.     )
  25.     lat = models.FloatField(
  26.         verbose_name=_("Latitude"),
  27.         help_text=_("Latitude"),
  28.         default=0.0,
  29.     )
  30.     lng = models.FloatField(
  31.         verbose_name=_("Longitude"),
  32.         help_text=_("Longitude"),
  33.         default=0.0
  34.     )
  35.     area_poly = models.MultiPolygonField(
  36.         verbose_name=_("Map area"),
  37.         help_text=_("Map area"),
  38.         blank=True,
  39.         null=True
  40.     )
  41.  
  42.     def __str__(self):
  43.         return "{}".format(self.name)
  44.  
  45.     class Meta:
  46.         verbose_name = _('District')
  47.         verbose_name_plural = _('Districts')
  48.  
  49. #FORM PARA USAR EL JS CUSTOM
  50. from leaflet.admin import LeafletGeoAdmin
  51.  
  52.  
  53. class DistrictForm(LeafletGeoAdmin):
  54.     class Media:
  55.         js = ('/static/js/district.js',)
  56.  
  57. #JS CARGADO CORRECTAMENTE
  58. (function($) {
  59.     var lat = $("input[name='lat']").attr("value");
  60.     var lng = $("input[name='lng']").attr("value");
  61.     $("#id_area_poly-map").on('map:loadfield', function (e) {
  62.         console.log(e.field, e.fieldid);
  63.     });
  64. })(django.jQuery);
  65.  
  66. #URL EN SETTINGS
  67. admin.site.register(District, DistrictForm)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement