views:

62

answers:

2

I have a simple webapp in Django for an iPhone app. I want to prompt the user to review our product, but just once. I then don't want to show that prompt again.

So would the best practise way of implementing this to be to add a new entry to the user profile model with a bolean field: "reviewed" - and then set that flag when the user completes the action?

I would then check for that entry in my template and display or not, the prompt.

I've not yet worked with database models, extended the user model, or saved to custom DB fields, so any thoughts or examples on this would be most welcome. I'm a little nervous as my site has live users and I won't want to break the user tables.

A: 

There are a variety of ways to do this. I suggest the following:

Django has a messaging framework, built by design to show messages to users only once when the software creates them. Whenever X is created/modified/deleted etc, you can add the message to the user via User.message_set.create(message='Whatever you like'). This will be shown to the user once. This relies on django sessions, which I assume you're using since you're relying on the built-in user model. These messages are stored in auth_message.

HTH

Jose Boveda
But how would I only set this message once, and where would I store that flag?
Tristan
I don't think auth_message is for this purpose.
Natim
+1  A: 

If you are using MySQL or PostgreSQL, you can do some ALTER TABLE without loosing any data.

In Django, it is quite easy to add a profile for the user. Make sure, to create the profile if it doesn't exist :

try:
    profile = request.user.get_profile()
except UserProfile.DoesNotExist:
    # If DoesNotExists, Create an empty one
    profile = UserProfile(user=request.user)
    profile.save()

More information here :

Natim
thanks Natim - I actually already have a profile (I'm using a reusable app django-basic-profiles), but I'm confused if I should add this Boolean field here, elsewhere and if its the _right_ thing to do.
Tristan
I would add the boolean here if there is only one. If you need other flags in the future, the best way is to create a model `Flag` with a name and a ManyToManyField(User) in it. If there is a link between the flag and the User it is True and if not it is False.
Natim
With this method will that flag be applied to current users in the system when I do the syncdb, or would I need to use something like django-evolution to accomplish that?
Tristan
If you add the Flag Models, the syncdb will be enough. For adding a field in the Profile, you cannot use django-evolution since it need to be installed before the first syncdb. But you can do the alter table by hand.
Natim
just to clarify Natim - sorry for all the questions, so a flag is special and can be added just with a syncDB and I can have multiple flags for multiple things for each user?
Tristan