views:

53

answers:

0

Hello,

I want to write an app that registers a userprofile and uploads an image at the same time, I've got my baseprofile registration done, now all I want is to upload a user image using ImageModel and link it to a user, how do I achieve this?. These are the models:

class BaseProfileImage(ImageModel):
member = models.ForeignKey(BaseProfile)

class Meta:
    ordering = ['-id']

The manager:

class PublicManager(models.Manager):
"""
Returns only members where is_public is True.
"""
def get_query_set(self):
    return super(PublicManager, self).get_query_set().filter(is_public=True)

and the base profile:

class BaseProfile(models.Model):
    """
    A simple profile field to hold the user's profile information.

    """    
    GENDER_MALE = 'M'
    GENDER_FEMALE = 'F'
    GENDERS = (
        (GENDER_MALE, 'Male'),
        (GENDER_FEMALE, 'Female'),
    )

    PROVINCE_CHOICES = ( 
        ('Gauteng','Gauteng'),
        ('Limpopo','Limpopo'),
        ('Mpumalanga','Mpumalanga'),
        ('Natal','Natal'),
        ('Noord-Kaap','Noord-Kaap'),
        ('Noordwes','Noordwes'),
        ('Oos-Kaap','Oos-Kaap'),
        ('Suid-Kaap','Suid-Kaap'),
        ('Vrystaat','Vrystaat'),
        ('Wes-Kaap','Wes-Kaap'),
        ('Namibie','Namibie'),
        ('Mosambiek','Mosambiek'),

    )      

    user = models.ForeignKey(User,
                             help_text='The user that this profile is associated with.')
    id_number = models.CharField(max_length=13)

    province = models.CharField(max_length=13,
                                help_text='Province that the user lives in',
                                choices=PROVINCE_CHOICES)
    school = models.CharField(max_length=20,
                              help_text='Optional, user school',
                              blank=True, null=True)

    gender = models.CharField(choices=GENDERS, max_length=1)
    dob = models.DateField()
    activation_code = models.CharField(max_length=6,
                                       help_text='Code used to activate public accounts.')
    date_activated = models.DateTimeField(default=None, blank=True, null=True,
                                          help_text='The timestamp of when the profile was activated.')
    premium_account = models.BooleanField(help_text='This is used to determine whether or not the user is a premium user or not.')
    date_created = models.DateTimeField(default=datetime.now(),
                                        help_text='The timestamp of when this profile was created.')   
    referred_by = models.CharField(max_length=15, default=None, blank=True, null=True,
                                          help_text='The cell number of the person who referred the user to the site.')  
    is_public = models.NullBooleanField(default=True, null=True, blank=True, help_text='Profile can be seen by anyone when checked.')

    objects = models.Manager()
    public = PublicManager()

    def image(self):
        """
        Convenience method for returning the single most recent member image.
        """
        member_images = self.memberimage_set.all()
        if member_images:
            return member_images[0]  

    def __unicode__(self):
        return '%s %s' % (self.first_name, self.last_name)