from django.db import models from django.contrib.auth.models import User from django.contrib import admin from django import forms from django.forms import ModelForm # # Defining models # # class EquipmentCapability(models.Model): name = models.CharField(max_length=200) def __unicode__(self): return self.name class EquipmentType(models.Model): name = models.CharField(max_length=200) maker = models.CharField(max_length=200) website = models.URLField(blank=True) capabilities = models.ManyToManyField(EquipmentCapability) def __unicode__(self): return self.maker + " " + self.name class Location(models.Model): lat = models.FloatField("Latitude") lon = models.FloatField("Longitude") name = models.CharField("Location name", max_length=200) locname = models.CharField("Town/city", max_length=200) website = models.URLField(blank=True) manager = models.ForeignKey(User) def __unicode__(self): return self.name class Equipment(models.Model): type = models.ForeignKey(EquipmentType) location = models.ForeignKey(Location) notes = models.TextField() def __unicode__(self): return self.type # # Registering tables with admin site # # admin.site.register(EquipmentType) admin.site.register(Location) admin.site.register(EquipmentCapability) admin.site.register(Equipment) # # Defining forms # # class LocationForm(ModelForm): class Meta: model = Location exclude = ('manager')