First time here? Check out the FAQ!

Revision history  [back]

Write a query using user object to get data from different table

I have created a new table which has auth_user table id as its foreign key. My new table has extra information of the user which I want to populate on the profile page of the user.

Here is the model of the new table:

class ShibUser(models.Model):
    auth_user = models.ForeignKey(User)
    shib_username = models.CharField(max_length = 200)
    shib_user_role = models.CharField(max_length = 200)

    class Meta:
        app_label = 'askbot'

Basically way I understand is that write the query but use objects. So I initially started by adding a field in the edit profile:

in askbot/forms.py

role = forms.CharField(
                    label=_('Role'),
                    required=False,
                    max_length=255,
                    widget=forms.TextInput(attrs={'size': 35})
                )

my next goal was to get the user role which is in the new table that I created based on the id of the auth_user table.

if askbot_settings.EDITABLE_SCREEN_NAME:
    self.fields['role'].initial = "test"

Currently I have put dummy "test", How can I accomplish this?