[Python] [pythonisti] definizione profilo pythonisti

Manlio Perillo manlio_perillo a libero.it
Gio 11 Gen 2007 17:07:38 CET


Manlio Perillo ha scritto:
> Per evitare di divagare su temi non fondamentali, direi di focalizzarci 
> sulla definizione del profilo degli utenti.
> 

Ecco la prima bozza:


from django.db import models
from django.contrib.auth.models import User


class Country(models.Model):
     # ISO country code
     country_code = models.CharField(maxlenght=2, primary_key=True)
     # Country name, in english
     country_name = models.CharField(maxlenght=30)
     # XXX TODO localized country name?


class Address(models.Model):
     """Address detail, based on the XAL Standard.
     """

     country = models.ForeignKey(Country)
     administrative_area = models.CharField(maxlength=50, blank=True)
     sub_administrative_area = models.CharField(maxlength=50, blank=True)
     locality = models.CharField(maxlength=50, blank=True)
     thoroughfare = models.CharField(maxlength=50, blank=True)
     postal_code = models.PositiveIntegerField(blank=True) # XXX check me


     def __str__(self):
         """Format the address in a form suitable for Google
         geodecoder.
         """

         return '%s %s %s %s %s %s' % (
             self.thoroughfare or '',
             self.locality or '',
             self.postal_code or '',
             self.sub_administrative_area or '',
             self.administrative_area or '',
             self.country.country_name
             )


class Profile(models.Model):
     username = models.OneToOneField(User)
     address = models.ForeignKey(Address) # XXX check me 1:1 relation
     # Path to user avatar
     avatar = models.CharField(maxlength=20, blank=True)
     # The company where the user works
     company = models.CharField(maxlength=50, blank=True) # XXX TODO

     for_hire = models.BooleanField()
     for_consultancy = models.BooleanField()


     def save(self):
         from pythonisti.geo.models import GeoLocation

         # Fill the GeoLocation table
         address = str(self.address)
         GeoLocation(username=self.username, location=address).save()

         return super(GeoLocation, self).save()


Manca ancora il modello per i Skill/Tags e quello per le References
(il social network di cui si parlava, ad esempio io ho lavorato con 
Lawrence e lo raccomando)



Saluti  Manlio Perillo


Maggiori informazioni sulla lista Python