[Answer]-Django – get values from a self-defined object

1👍

Instead of ControlInformation = request.user.get_profile() use:

instance = ControlInformation.objects.get(user=request.user)

Some more tips:

  • Use ModelForm to automagically create a form from your model.

  • You can use a BooleanField instead of ON/OFF.

And you can use one lookup for two fields:

  TEMP = (
        ('HIGH', 'High'),
        ('MEDIUM', 'Medium'),
        ('LOW', 'Low'),
  )

Enjoy Django!

👤Udi

Leave a comment