Re: Problem with CircularDependency Model
Thank you very much for the great answer! You are correct, I didn't had a clear understanding of the RelatedObject Principle. I think I added this when I was fiddling with the rest framework. Of course, I also had thought about making MasterUser a boolean, but I need to ensure that there is only one MasterUser. I thought about doing it in the Code, but I thought it might be better to enforce it at Database Level. However, I think your solution is much better. I also thought having a separate Table for the MasterUser Relationship, like you suggested. I tried to some find some suggestions on how to model a relationship like that. I think, I will go for the boolean field but my intuitive assumption would be to overwrite the pre_save method. post_save kinda sounds like it is too late at that point. Anyway, thanks a lot for you recommendations! On Friday, May 19, 2017 at 5:50:42 PM UTC+2, Melvyn Sopacua wrote: > > > > Yep, let me see if I got it right: > > - The User model is defined as AUTH_USER_MODEL in settings.py > > - User points to institute > > - Institute points to User > > > > So it is in fact a circular dependency on the model level as well. And one > you don't need. > > > > From the way you defined the related_name it is also clear you don't get > the RelatedObject principle of Django. > > > > A ForeignKey creates a bridge between two models: you can travel in both > directions. Using your models: > > > > class User(AbstractBaseUser, PermissionsMixin): > > username = ... > > > > class Institute(models.Model): > > master_user = models.ForeignKey(settings.AUTH_USER_MODEL, > related_name='institute') > > members = models.ManyToManyField(settings.AUTH_USER_MODEL) > > > > Because of the ForeignKey on Institute, Django creates an attribute on > User, called 'institute'. It uses institute, because I specified that as > related_name. You could use a different name there, but it has to be a name > that can be used on the model you point to. > > > > However, this isn't a good representation of realitity, given your own > description. > > So this is a better way to do it: > > > > class User(AbstractBaseUser, PermissionsMixin): > > institute = models.ForeignKey('port.Institute', related_name='members') > > is_master_user = models.BooleanField(default=False) > > > > class Institute(models.Model) > > name = models.CharField(max_length=255) > > # members is now created by the foreign key > > @property > > def master_user(self): > > return self.members.get(is_master_user=True) > > > > This model is much simpler. All you need to do is to verify that when > someone is made master user, that all other members of the institute are > *not* master user. > > > > You can do this in a post_save signal or in the clean method of User , > both with its own caveats. > > > > Another way would be to define a MasterUser model, which is easier to > maintain in the admin: > > > > class MasterUser(models.Model): > > # Assume one person can be master user of many institutes > > # if not, this also has to be a OneToOneFIeld > > user = models.ForeignKey(settings.AUTH_USER_MODEL) > > institute = models.OneToOneField(Institute, related_name='master_user') > > -- > > Melvyn Sopacua > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8c82ccfa-769f-4218-bff5-5adb7d851f97%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Problem with CircularDependency Model
No, I am trying to deploy it locally. I have no sqlite DB and no migrations. For some strange reason I used to just run manage.py makemigrations and would create the initial migrations for all Apps. This doesn't work for some reason anymore. So I have to to makemigrations APPname for each app and when I run to migrate to create the intial database schema, it doesn't work. So I figured my Data Model is crap. On Wednesday, May 17, 2017 at 5:41:41 PM UTC+2, Melvyn Sopacua wrote: > > On Wednesday 17 May 2017 05:57:57 Tobias Dacoir wrote: > > > Thanks Melvyn, > > > > > > I used promises before, when I use a foreign key for a class that is > > > not yet defined, however it didn't change anything for my problem. I > > > can make migrations, but not migrate. I am starting with a new > > > database from scratch. > > > self.ensure_not_cyclic(target, lambda x: (parent.key for parent in > > > self. node_map[x].parents)) > > > File > > > "/Users/no68tuh2/.virtualenvs/ihearu/lib/python2.7/site-packages/djang > > > o/db/migrations/graph.py" , line 370, in ensure_not_cyclic > > > raise CircularDependencyError(", ".join("%s.%s" % n for n in > > > cycle)) django.db.migrations.exceptions.CircularDependencyError: > > > play.0001_initial, portal.0001_initial > > > > > > This CircularDependencyError is driving me crazy. > > > > Ah, now I see! > > This has nothing to do with *model* dependencies. Two *migrations* depend > on each other: play and port, both 0001_initial. > > > > Do you have any idea how you got into that jam? Did you fiddle with > django_migrations table? Maybe run --fake? > > -- > > Melvyn Sopacua > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5bb45dcf-9ced-44b9-96fe-345ab9e0dec3%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Problem with CircularDependency Model
I am not sure if this is solution but instead of running makemigrations first, I ran migrate --run-syncdb. That got me past this error. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8bb9c8f8-fd97-4331-bdbd-be01473fa67d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Problem with CircularDependency Model
Thanks Melvyn, I used promises before, when I use a foreign key for a class that is not yet defined, however it didn't change anything for my problem. I can make migrations, but not migrate. I am starting with a new database from scratch. self.ensure_not_cyclic(target, lambda x: (parent.key for parent in self. node_map[x].parents)) File "/Users/no68tuh2/.virtualenvs/ihearu/lib/python2.7/site-packages/django/db/migrations/graph.py" , line 370, in ensure_not_cyclic raise CircularDependencyError(", ".join("%s.%s" % n for n in cycle)) django.db.migrations.exceptions.CircularDependencyError: play.0001_initial, portal.0001_initial This CircularDependencyError is driving me crazy. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ed4e63f1-ae28-405f-b6ec-6dce38c2f386%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Problem with CircularDependency Model
Thanks for the suggestion, but I the migration by itself is not the only problem. I still have the feeling I should fine-tune the model somehow. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/884d4bc5-af88-484f-bc9b-e760796fc9f0%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Problem with CircularDependency Model
I am trying to build a model (in two separate apps) which has the following constraints: - There can be many institutes - there can many users - each user is a member of exactly one institute - each institute has exactly one master user However I am running into CircularDependency errors when trying to create this model and database. Of course this model is a bit problematic because you can't have an institute without master user, but also you can't create a user without some default institute. How do I fix this? Should I be more lean on the model side and allow for a lot of blanks and null values and make all the exception handling somewhere else? Please tell me how to improve my model. > >> class User(AbstractBaseUser, PermissionsMixin): > > # account-related information > institute = models.ForeignKey(Institute, blank=True, null=True, > on_delete=models.SET(get_default_institute)) > username = ... > > > This is the model in another app for the institutes > > class Institute(models.Model): > master_user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name > ='master_user') > name = models.CharField(max_length=255) > > def members(self): > UserModel = apps.get_model('play', 'User') # need to avoid > circular import > return UserModel.objects.filter(institute=self) > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6243e47f-f526-4d08-88ac-07034583201c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: How to update a live / deployed Django project?
Thanks for all the great input. I'll definetely look into salt too (only worked with puppet so far) but for now I guess fabric will be fine. We are using Python 2.7 everywhere anyway. Like I said, right now we plan to host it on a single physical machine that we get from the university (it's a research project). But I see that nobody is using the Apache / WSGI solution that is explained in Django's documentation. So I'll also have to look into nginx + gunicorn as well. Phew...seems like even more work than actually developing our webapp :) -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/786c01bc-36d0-45ff-9d33-890db0b5ab50%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: How to update a live / deployed Django project?
Thanks for sharing your workflow. Sounds simple enough and is more or less a scripted version of what I had in mind all along. About the manual intervention: At some points during development we had to provide a one-time manual entry when Django was migrating the database, either by adding or removing properties to existing models. This shouldn't happen after we go live with 1.0 - hopefully. We always have ideas for new features to be build in :) -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2566cd3d-478b-4276-aba7-3917141ae104%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: How to update a live / deployed Django project?
Thanks for the reply. Thanks for the advice. We should include the migrate command into our git hook as well. But like I said, sometimes it's not always possible as manual interaction is required. At least for 1.0 our model should not change much, except for future extensions and new models. We also have a development / test server that is a direct clone of the future live server. However I still don't have the workflow laid out. Should we use KISS and just upload a zip of our new version and just replace the whole folder on the live server with the new code and issue an Apache restart afterwards (not even sure that this is needed in order to pick up the new code)? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a8ae9869-83cb-4023-a884-91ebf8190724%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
How to update a live / deployed Django project?
We've build a small web application using Django 1.8 over the past couple of months and we are going live with version 1.0 soon (one last closed beta test is coming up). So far we have deployed it on an Ubuntu VM (in Azure) using Apache / Nginx and a local MySQL Server. I've already found some good tutorials on how to properly set it up (http://rogueleaderr.com/post/65157477648/the-idiomatic-guide-to-deploying-django-in#disqus_thread ) however what I am mising now is how to handle updates to our code. For our development server we have a git hook that automatically deploys new commits to the server. However that often requires manual interaction - running manage.py makemigrations etc. Sometimes Django also does not pick up our changed models and we have to manually fiddle with the Database in order to get it back running. We even had times where we lost all our data since it was easier to just start with a new database. Obviously this can't happen once we are live and obviously we want downtime to be as small as possible. So is there any guide on how to update code of a live, deployed Django application? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9f89dfc1-4fa5-486b-92ae-ace24238dc3f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Do Signals block Django process?
Thanks for the info about django-debug-toolbar. I will certainly test it. I assume that I do a quite a lot of slow queries, but during development I run with a very reduced dataset, so my database (sqlite too instead of mysql) only contains a couple of hundred entries whereas in deployment it will be 10.000+. Still hopefully I can get some estimates which queries take how long to finish right now and optimize those. And in a 2nd stage I need some kind of tool to simulate multiple users login in and filling out forms on the site to see how it behaves. I found a couple of names using google, however I still have to settle for one tool that is still maintained and well documented. Any recommendations in that area are welcome. On Saturday, January 31, 2015 at 1:57:55 AM UTC+1, Tundebabzy wrote: > > > The view will return after the receiver has finished its work. But are you > doing any slow queries? I ask because you might be over engineering your > work. > > A good place to start is to benchmark your queries using a tool like > django-debug-toolbar. With that you can know exactly how long it takes one > user to query your database and then use that to estimate for more users. > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c85156f9-e36e-4a17-ad64-744802736fda%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: How to get hold of a session after getting signaled?
I can't just call badge.award_to(user) because I need to wait for the check logic to verify if the user should receive a badge or not. My workaround is that I created a new table that inserts badge and user foreign keys and before the view is rendered I will check this table for any entries for that user. If there are, I will copy the data to a message and delete the object from the database again. It's rather ugly due to the many database hits which I would like to avoid but I can't think of anything else at the moment. Apparently (using google) there is no way to get hold of the request in a post_save() signal - which I need to check all achievements. The only real solution would be to not use this post_save() signal but manually do the checking for achievements before my view is rendered, which would require some work on the original source code. I will look into it though next week. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ee9653c8-2c8e-479e-871b-34774862888b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Best Practices Model Design
Hi, I'm quite new to Django myself. I doubt anyone is going through your whole Models File. You should have at least copy & pasted it from some kind of IDE to preserve the indention level. As for your other questions about the url to user-/profilename, have you looked at the tutorial: https://docs.djangoproject.com/en/1.7/intro/tutorial03/ There the urls.py is explained. In their example question_id is used, but I bet you could use something else as well. Or go with the user_id (that's what I did, of course doesn't look so pretty). And about the file upload - I didn't rename the files yet, but it's good practice, so I looked up the documentation and apparently you can overwrite the filename. I will have to try this out too later: https://docs.djangoproject.com/en/1.7/ref/models/fields/#django.db.models.FileField -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8ba0d61e-4374-4391-b7c9-45b49253499d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Changing many-to-many using Admin Site never calls post_remove Signal
not very nice, and probably not pythonic (still learning) but now I added another two for loops to find old references and delete them: if action == "post_add": if isinstance(instance, Database): # then update pairs for a in instance.audioData(): for q in instance.questions.all(): pair = AudioQuestionPair.objects.get_or_create(audioData =a, question=q, database=instance) for choice in q.get_choices(): answer = Answer.objects.get_or_create(body=choice, audioQuestionPair=pair[0]) # check for removed questions and delete pairs pairs = AudioQuestionPair.objects.filter(database=instance) toDelete = [] for pair in pairs: if pair.question not in instance.questions.all(): toDelete.append(pair) for item in toDelete: item.delete() On Friday, January 30, 2015 at 9:44:29 PM UTC+1, Tobias Dacoir wrote: > > I have a many-to-many relationship which the Admin can change using the > Admin Site. I use a ModelAdmin.filter_horizontal, but even with the default > widget it's the same. > > I registered a receiver when m2m_changed, however it always only calls: > pre_clear, post_clear, pre_add, post_add, in that order. > > Now for post_add I have code to execute, to create new objects in the > database, however when a value is removed from this many-to-many field, I > need to delete some objects. Since pre_remove is never called, I can't tell > which value was removed and I'm unable to find out which objects to delete. > > Is there a way to modify the Admin page to actually call remove / add on > the Model? Or I need another way to find out which value was removed. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/83eb139a-3732-4986-ad8a-12e36e9c8c1c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Changing many-to-many using Admin Site never calls post_remove Signal
I have a many-to-many relationship which the Admin can change using the Admin Site. I use a ModelAdmin.filter_horizontal, but even with the default widget it's the same. I registered a receiver when m2m_changed, however it always only calls: pre_clear, post_clear, pre_add, post_add, in that order. Now for post_add I have code to execute, to create new objects in the database, however when a value is removed from this many-to-many field, I need to delete some objects. Since pre_remove is never called, I can't tell which value was removed and I'm unable to find out which objects to delete. Is there a way to modify the Admin page to actually call remove / add on the Model? Or I need another way to find out which value was removed. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2b9b7689-ded9-4e7a-88c5-5775e70268f2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: using Django on an existing mysql schema
I'm certainly no Django expert, but I'm not sure if you can use the orm and an already existing database. However the documentation states that you can write all queries yourself, essentially not using the orm. However if you do that, I'm wondering why you want to use Django at all? And pushing business logic into the database sounds like bad design to me (model and controller should be decoupled in MVC like patterns). About the signed and unsigned changes - did you check the documentation: https://docs.djangoproject.com/en/1.7/ref/models/fields/ And enum is (afaik) not available in Python, maybe that's why it changed it to char. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b7bd5fcc-4093-401e-84fc-8c3175d9ee68%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Do Signals block Django process?
Thanks for always answering my questions :) I did read the documentation on uWSGI and I think I have an understanding now of workers and threads (from Webserver or uWSGI) and how it handles multiple users. For the signals and badge calculation, I did see celery pop up a couple of times and I did briefly look at their documentation. In theory I don't need this though because when the user submits a form, I want to check for achievements before showing him the results page. If I use celery then it might happen that the new view is rendered while the achievements are still being processed. Maybe I will have to go this route at some point but then I face two new problems (one of which I already have): a) I need to figure out how to get the request that won a badge in order to send him a message (for this I opened an extra thread) b) I would need to modify his current view, something like using Websocket. I did a quick google search in the past and apparently using websocket and django is not so easy. So if I can avoid it, I'm happy. If I know that the signals are processed in sync, and before the new view is rendered, then I can just have the code after the signal check if a badge has been awarded and then render the view. Phew, still quite complicated. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a1f83580-11fc-414d-b806-9a0e5ed106ab%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
How to get hold of a session after getting signaled?
I'm using django-badges in my project which can emit a signal when a user is awarded a badge. I was able to implemented a receiver function, however the output is the following: signals.py (from badges): import django.dispatch badge_awarded = django.dispatch.Signal(providing_args=['user', 'badge']) my receiver function test: from badges.signals import badge_awarded @receiver(badge_awarded) def do_something_after_badge_awarded(sender, user, badge, **kwargs): print "Badge Signal received" print sender # print user # user object print badge # badge object print kwargs and the output was: Badge Signal received player1 Test Badge 2 {'signal': } I want to add a message to the request, to notify or show the user that he earned a badge. Is it possible someone get hold of the request? I can freely modify the original source code from django-badges. Currently it's invoked by post_save() on a model instance. So I doubt I can get the request from there. I found a solution to add another 3rd party app which is called django-notification, but I don't want to add too many apps to my project. Another solution might be to just set some variable in the database and in my view to query this variable - however that will also cost performance and two database hits. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5e8f655c-8385-46aa-94ae-2c5baef2034a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Do Signals block Django process?
I just added django-badges to my project. Basically it can award Badges if Users fullfill certain requirements. For this, everytime I call user.save() django-badges receives the post_save() signal and starts checking. Now my project is similar to an online quiz, where users submit forms to answer questions. Right now I only have tested it locally and I'm not sure how to simulate multiple users accessing the page at the same time. When later run on production in combination with a webserver, will Django spawn a new thread for each connection / user? Or will there be only one thread, so if two users are accessing the website, the 2nd has to wait until the request from the first user is processed? Also what about my signal to process the badges. If I have a function that calls user.save(), which then signals to the badges module, will the execution of the original function stop until the signal has been processed or not? def myView(request): do_something() request.user.save() # signal emitted # ... render(view) So in this case, will the view be rendered immediately or only after the receiver for the signal has finished doing it's work? In my case I don't really need it to be asynchronous as long as the badge checking is fast enough and doesn't block the website for other users. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f3b2f9dd-4681-48a1-8d49-79f73d45d0eb%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: How to detect (daily) User Login when using cookies?
Thanks. Though I do not use a Custom Authentication Backend, it should be possible to inherit from the Default one and just overwrite the get_user Method. I will test it out. On Friday, January 30, 2015 at 3:56:10 PM UTC+1, Tom Evans wrote: > > On Fri, Jan 30, 2015 at 1:50 PM, Collin Anderson> wrote: > > Hi, > > > > If you use a custom authentication backend, you could update it every > time > > get_user(request) is called. > > > > HTTP is stateless, authentication happens every request, so that gets > called on every request, causing session modification on each request. > > How about: > > from django.utils import timezone > > class DailyLoginMiddleware(object): > def process_request(self, request): > if request.user.is_authenticated(): > today = timezone.now().strftime('%Y%m%d') > if request.session.get('last_seen') != today: > request.session['last_seen'] = today > setattr(request, 'new_today', True) > > Store todays date in the session, check to see if it is changed, only > modify the session if the date has changed, set an attribute on the > request so that later views can include that information. > > Cheers > > Tom > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0a7e4a2e-2f05-45e4-9633-14d60dce78a8%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: When do I have to call save() on a Model Instance?
Thanks for answering all my questions. So it's perfectly save to call the save method at a later time? As long as I keep the object and a pointer to it in memory I can freely modify it in several Functions before finally calling save at some point in time? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/60e58468-7575-419a-80ff-67ba804988eb%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
When do I have to call save() on a Model Instance?
I want to reduce the database queries, imagine I have a case like this: def function1(): user = User.objects.get(id=1) user.name ="Myself" function2() function3(user) user.save() def function2(): user = User.objects.get(id=1) user.lastname = "private" def function3(user): user.age = 18 Even if this works (haven't tested it yet and I can imagine that at least function2() might be a problem), should I immeditately call .save() in each of those functions? Or is it possible to freely modify the model and save it at a later stage? If so, function2() would not see the new value of user.name of course, however function3 should be able to see it (but probably not user.lastname). Is there a best practice? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/18ac4a4d-b1c2-4b36-af6c-5f0932a9ba2e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Best way to get ForeignKey Related Objects?
Damn, you are right. pair.answers() works. I'm wondering why I didn't get a syntax error when calling it without the parenthesis (), because print still worked. On Thursday, January 29, 2015 at 2:59:56 PM UTC+1, Vijay Khemlani wrote: > > "answers" seems to be a method on the AudioQuestionPair class, so your > call should be: > > for answer in pair.answers(): > print answer > > and "pair.answers.get.all()" does not make sense sinse "answers" is a > method. > > If you don't want to use a specific method, you can do this: > > answers = pair.answer_set.all() > > > On Thu, Jan 29, 2015 at 10:51 AM, Tobias Dacoir <fal...@gmail.com > > wrote: > >> I have two Models as shown below. Now when I have a specific >> AudioQuestionPair and I do something like >> >> print pair.answers >> >> >> >> it works just fine. However I can not do: >> >> for answer in pair.answers >> >> >> >> Using pair.answers.get.all() does also not work. So I have to do >> >> answers = Answer.objects.filter(audioQuestionPair=pair) >> >> >> >> Isn't there a better way to design this? I can imagine that using >> objects.filter is more taxing on the database and uses more time than maybe >> another method? >> >> >> class AudioQuestionPair(models.Model): >> audioData = models.ForeignKey(AudioData) >> question = models.ForeignKey(Question) >> database = models.ForeignKey(Database) >> votes = models.PositiveIntegerField(default=0) >> >> class Meta: >> verbose_name = "AudioData-Question Pair" >> verbose_name_plural = "AudioData-Question Pairs" >> >> def answers(self): >> return Answer.objects.filter(audioQuestionPair=self.pk) >> >> def __str__(self): >> return "Database %s: AudioData %s - Question %s with %s Votes >> and Answers: %s" % (self.database, self.audioData, self.question, self. >> votes, self.answers()) >> >> """ >> Answer for a specific Audio-Question Pair >> cumulative >> """ >> class Answer(models.Model): >> body = models.CharField(max_length=255) >> count = models.PositiveIntegerField(default=0) >> isGroundtruth = models.BooleanField(default=False) >> audioQuestionPair = models.ForeignKey(AudioQuestionPair) >> >> class Meta: >> verbose_name = "Answer to AudioQuestionPair" >> verbose_name_plural = "Answers to AudioQuestionPairs" >> >> def __str__(self): >> return "%s - %s times" % (self.body, self.count) >> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django-users...@googlegroups.com . >> To post to this group, send email to django...@googlegroups.com >> . >> Visit this group at http://groups.google.com/group/django-users. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/e8991d3a-1d32-4655-918f-26e0877898de%40googlegroups.com >> >> <https://groups.google.com/d/msgid/django-users/e8991d3a-1d32-4655-918f-26e0877898de%40googlegroups.com?utm_medium=email_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b66b75b7-4d6d-43ef-a72f-215b85e8c08c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Best way to get ForeignKey Related Objects?
I have two Models as shown below. Now when I have a specific AudioQuestionPair and I do something like print pair.answers it works just fine. However I can not do: for answer in pair.answers Using pair.answers.get.all() does also not work. So I have to do answers = Answer.objects.filter(audioQuestionPair=pair) Isn't there a better way to design this? I can imagine that using objects.filter is more taxing on the database and uses more time than maybe another method? class AudioQuestionPair(models.Model): audioData = models.ForeignKey(AudioData) question = models.ForeignKey(Question) database = models.ForeignKey(Database) votes = models.PositiveIntegerField(default=0) class Meta: verbose_name = "AudioData-Question Pair" verbose_name_plural = "AudioData-Question Pairs" def answers(self): return Answer.objects.filter(audioQuestionPair=self.pk) def __str__(self): return "Database %s: AudioData %s - Question %s with %s Votes and Answers: %s" % (self.database, self.audioData, self.question, self.votes, self.answers()) """ Answer for a specific Audio-Question Pair cumulative """ class Answer(models.Model): body = models.CharField(max_length=255) count = models.PositiveIntegerField(default=0) isGroundtruth = models.BooleanField(default=False) audioQuestionPair = models.ForeignKey(AudioQuestionPair) class Meta: verbose_name = "Answer to AudioQuestionPair" verbose_name_plural = "Answers to AudioQuestionPairs" def __str__(self): return "%s - %s times" % (self.body, self.count) -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e8991d3a-1d32-4655-918f-26e0877898de%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: How to detect (daily) User Login when using cookies?
Yes that would be enough. I know in the User Model there is last_login but that is only updated when the User actually logs in. And the signal from django-allauth is also only send when the user uses the login form. The only other alternative I found was to check in every view I have for request.user and store / update datetime.now. But this is quite ugly. On Tuesday, January 27, 2015 at 9:00:15 PM UTC+1, Collin Anderson wrote: > > Hi, > > Would it make sense to simply keep a record of when the last time you've > seen the user is? > > Collin > > On Friday, January 23, 2015 at 4:43:41 AM UTC-5, Tobias Dacoir wrote: >> >> I'm using django-allauth and I receive a signal when a user logs in. Now >> I want to store each day the user logs in. However, when the user does not >> logout he can still log in the next day thanks to the cookies. I know that >> I can set SESSION_EXPIRE_AT_BROWSER_CLOSE to True in settings.py. But this >> may annoy some Users. >> >> So is there a way to use cookies but still tell if a User has accessed >> the site for the first time today? >> > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e208c5f2-2669-4305-a2c0-89ef866de459%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
How to detect (daily) User Login when using cookies?
I'm using django-allauth and I receive a signal when a user logs in. Now I want to store each day the user logs in. However, when the user does not logout he can still log in the next day thanks to the cookies. I know that I can set SESSION_EXPIRE_AT_BROWSER_CLOSE to True in settings.py. But this may annoy some Users. So is there a way to use cookies but still tell if a User has accessed the site for the first time today? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0acff60c-f658-4f2a-8318-47e08a6ffe98%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Dynamically show or hide form fields?
ok, seems I'm stupid. The fields already have an id set, so I should be able to use javascript. Sorry for asking this stupid question. Still if someone has valid points as why I should use a different solution please let me know. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/85ea8045-6245-4b1b-8434-013629b8b008%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Dynamically show or hide form fields?
In my Signup form the user has to chose his languages and afterwards his proficiency in that language. So based on the selection from forms.ChoiceField it should display one of two other ChoiceFields. Example: Language = English -> Display English Proficiency below Language = German -> Display German Proficiency below Currently both Proficiency fields are always shown. I did some searching on how to accomplish this and I came up with buzzwords like AJAX (using dajax) or Crispyforms (3rd Party App) but it shold be possible to use simple javascript as well. I don't want to include another 3rd party app if possible since I use this for my signup form which is from django-allauth. The Signup form is inheriting from forms.Form currently: class SignupForm(forms.Form): I don't know what will happen to django-allauth if I change this to something else. In the template it just calls {{ form.as_p }} so I have no idea on how to set custom classes / id's on those form fields. I didn't find anything about this in Django Documentation here: https://docs.djangoproject.com/en/1.7/ref/forms/fields/#choicefield Can anyone please tell me what the best solution would be? If I have to include some 3rd party app is it likely to break django-allauth for the Signup form? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dea48b6b-0a62-4f5f-a9e4-570608d8bebd%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Re-Order rendering of input fields of django-contact-form?
Ah it works. After I restarted Django and hit F5 again it re-orders it now. So the code above is the solution. Thanks! -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/49953ca8-9cf5-4eae-acfa-ecfc40f4ad44%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Re-Order rendering of input fields of django-contact-form?
It still complained about the request, but I was finally able to get it to work using this code: def __init__(self, request, *args, **kwargs): super(CustomContactForm, self).__init__(request=request, *args, ** kwargs) fields_keyOrder = ['name', 'reason', 'email', 'body'] if (self.fields.has_key('keyOrder')): self.fields.keyOrder = fields_keyOrder else: self.fields = OrderedDict((k, self.fields[k]) for k in fields_keyOrder) However it still does not re-order the fields, I searched stackoverflow again and found this for Django 1.7: https://github.com/pennersr/django-allauth/issues/356#issuecomment-24758824 But it still does not work. The order doesn't change it all. sigh :( -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f9ad446d-432d-40bd-90c7-7bbb9d484b5a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Re-Order rendering of input fields of django-contact-form?
Unfortunately this doesn't work as the contact form needs to be passed the request as well. I tried to modify the call to super but it didn't work. As a workaround what I did now was to look at the HTML Code that the tag {{ form.as_p }} creates, and copy and paste that into the HTML template instead of using {{ form.as_p }}. Then I can freely shuffle around my fields, however for stuff like Choice Widgets, I need to supply the options in the HTML code as well, which is quite troublesome. So far I still haven't found a real solution. :( -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/080a9ff8-2a05-4af6-aba6-075530e40f8c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re-Order rendering of input fields of django-contact-form?
I'm using django-contact-form which allows me to subclass it and add custom fields to it. However all my added fields will appear at the bottom. I even tried overwriting the original fields but still the order they appear is wrong. How can I control this? I tried searching for an answer, but only found ModelForm info that didn't work as the parent just inherits from forms.Form and is not a ModelForm. Parent Class cound be found here: https://bitbucket.org/ubernostrum/django-contact-form/src/4b7d2fa20c1d01568fb7c4c800155378e176923b/contact_form/forms.py?at=default My overwritten class: class CustomContactForm(ContactForm): REASON = ( ('support', 'Support'), ('feedback','Feedback'), ) reason = forms.ChoiceField(choices=REASON, label='Reason') name = forms.CharField(max_length=100, label=u'Your name') email = forms.EmailField(max_length=200, label=u'Your email address') body = forms.CharField(widget=forms.Textarea, label=u'Your message') and my template: {% extends 'base.html' %} {% block body_block %} Contact Form To send us a message fill out the below form. {% csrf_token %} {{ form.as_p }} {% endblock %} -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/725a9615-1d66-430a-8dbd-c7b1e70a7920%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: How to subclass django-contact-form to create custom contact form?
I managed to do it! Thanks to your help. Ok all you need to do is this: views.py: class ReportFormView(FormView): form_class = ReportForm template_name = 'contact_form/contact_form.html' def form_valid(self, form): form.save() return super(ReportFormView, self).form_valid(form) def get_form_kwargs(self): # ContactForm instances require instantiation with an # HttpRequest. kwargs = super(ReportFormView, self).get_form_kwargs() kwargs.update({'request': self.request}) return kwargs def get_success_url(self): # This is in a method instead of the success_url attribute # because doing it as an attribute would involve a # module-level call to reverse(), creating a circular # dependency between the URLConf (which imports this module) # and this module (which would need to access the URLConf to # make the reverse() call). return reverse('contact_form_sent') Add this to URL patterns: url(r'^report/', ReportFormView.as_view(), name='report_form'), and in forms.py subclass like this: class ReportForm(ContactForm): additional = forms.CharField(max_length=100, label='additional field test') subject_template_name = "contact_form/report_form_subject.txt" template_name = 'contact_form/report_form.txt' And the template, thanks to you is easy as pie: report.html: {% extends 'base.html' %} {% block body_block %} Contact Form To send us a message fill out the below form. {% csrf_token %} {{ form.as_p }} {% endblock %} Now I just need to figure out how to pre-fill. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f0107dff-039b-446d-9f33-aa7f0cd640e6%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: How to subclass django-contact-form to create custom contact form?
Thanks for the reply. I was wondering about the if statement about request.type as well, but I took the code from Stackoverflow and a combination of the original source code. It calls a Class.as_view() and I wasn't sure if I need to overwrite that as well. I didn't really want to write all the view code logic again as it kinda defeats the purpose of having a 3rd party app that does that for me. According to the official documentation I'm still unsure if I need to type anything in my views.py at all. As far as I understand this, I just need to subclass ContactForm somehow: class ContactForm(forms.Form): """ The base contact form class from which all contact form classes should inherit. If you don't need any custom functionality, you can simply use this form to provide basic contact functionality; it will collect name, email address and message. The ``ContactForm`` view included in this application knows how to work with this form and can handle many types of subclasses as well (see below for a discussion of the important points), so in many cases it will be all that you need. If you'd like to use this form or a subclass of it from one of your own views, just do the following: 1. When you instantiate the form, pass the current ``HttpRequest`` object to the constructor as the keyword argument ``request``; this is used internally by the base implementation, and also made available so that subclasses can add functionality which relies on inspecting the request. 2. To send the message, call the form's ``save`` method, which accepts the keyword argument ``fail_silently`` and defaults it to ``False``. This argument is passed directly to ``send_mail``, and allows you to suppress or raise exceptions as needed for debugging. The ``save`` method has no return value. Other than that, treat it like any other form; validity checks and validated data are handled normally, through the ``is_valid`` method and the ``cleaned_data`` dictionary. taken from here: https://bitbucket.org/ubernostrum/django-contact-form/src/4b7d2fa20c1d01568fb7c4c800155378e176923b/contact_form/forms.py?at=default -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5c5e5b0a-fcb8-4928-b696-1f6c48e6e951%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: How to subclass django-contact-form to create custom contact form?
According to the official documentation I'm still unsure if I need to type anything in my views.py at all. As far as I understand this, I just need to subclass ContactForm somehow: class ContactForm(forms.Form): """ The base contact form class from which all contact form classes should inherit. If you don't need any custom functionality, you can simply use this form to provide basic contact functionality; it will collect name, email address and message. The ``ContactForm`` view included in this application knows how to work with this form and can handle many types of subclasses as well (see below for a discussion of the important points), so in many cases it will be all that you need. If you'd like to use this form or a subclass of it from one of your own views, just do the following: 1. When you instantiate the form, pass the current ``HttpRequest`` object to the constructor as the keyword argument ``request``; this is used internally by the base implementation, and also made available so that subclasses can add functionality which relies on inspecting the request. 2. To send the message, call the form's ``save`` method, which accepts the keyword argument ``fail_silently`` and defaults it to ``False``. This argument is passed directly to ``send_mail``, and allows you to suppress or raise exceptions as needed for debugging. The ``save`` method has no return value. Other than that, treat it like any other form; validity checks and validated data are handled normally, through the ``is_valid`` method and the ``cleaned_data`` dictionary. taken from here: https://bitbucket.org/ubernostrum/django-contact-form/src/4b7d2fa20c1d01568fb7c4c800155378e176923b/contact_form/forms.py?at=default -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/19bfb8e0-9981-4659-b050-e4cb6e47025d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: How to subclass django-contact-form to create custom contact form?
Thanks for the reply. I was wondering about the if statement about request.type as well, but I took the code from Stackoverflow and a combination of the original source code. It calls a Class.as_view() and I wasn't sure if I need to overwrite that as well. I didn't really want to write all the view code logic again as it kinda defeats the purpose of having a 3rd party app that does that for me. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ff62ddad-8c05-49c7-97c1-6108f1550e88%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
How to subclass django-contact-form to create custom contact form?
I need to include two different contact forms in my app. One a general contact form and another Report / Feedback form that pre-fills some data depending on which site it was called from. So I hit google, found django-contact-form, installed it and after creating some basic templates (and rest of the configuration) I was able to make use of /contact/ to present a basic form which takes in Name, Email and Message. Works fine. Now I need that Report Form. The idea is to have a 'Report' Button on the Website which maps to /report/$Parameter (or maybe it will just put the parameter into request, not sure yet how to do this). However I have troubles getting my Custom Form to work. I tried to create a new view that uses my custom form which just inherits from ContactForm: forms.py: class ReportForm(ContactForm): additional = forms.CharField(max_length=100, label='additional field test') subject_template_name = "contact_form/report_form_subject.txt" template_name = 'contact_form/report_form.txt' views.py: def report(request): reportForm = ReportForm return render(request, 'play/report.html', {'form': reportForm}) template report.html: {% extends 'base.html' %} {% block body_block %} Report Form To send us a message fill out the below form. {% csrf_token %} Name: Your e-mail: additional field test: Message: {% endblock %} However it's not working at all. I can see the form displayed thanks to the HTML Template, but nothing is happening when I press Submit. There is no example on the website on how to subclass it :( http://django-contact-form.readthedocs.org/en/latest/quickstart.html Or should I just copy and paste the whole code from here and adapt it to include additional fields: https://bitbucket.org/ubernostrum/django-contact-form/src/4b7d2fa20c1d01568fb7c4c800155378e176923b/contact_form/forms.py?at=default -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e72e813c-d78b-433f-8444-e76a4129c862%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Which 3rd Party (Social) Auth App should I use?
After more reading and experimenting I think I will use django-allauth. It allows local and social auth and signup. And I was able to customize the local signup form very easily (thanks to stackoverflow). -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ad07bc1f-f1e0-4936-8bef-9a5fe3b94b2f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Best Tutorial
After doing the official tutorial I also worked through this one: http://www.tangowithdjango.com/ Anything else you can find with Google, if you have specific problems there are tons of blog posts, video tutorials and so on. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8bf9ae4f-d3c0-40ff-91cf-8d9fa5c441d9%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: hello need help to configure django
I'm also new to Django but to me it seems that you have not registered any App in settings.py. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3c02b1ea-5678-4d08-9966-a5f0f1bcf280%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Which 3rd Party (Social) Auth App should I use?
Thanks for the link. That explain's how I can inject my logic and hopefully form into the authentication process. Still quite complicated for a beginner. I did some more reading and apparently I need django-registration-redux for local registration (and stuff like password reset) and then a 2nd addon for social auth. Still I'm not quite sure what the difference between django-allauth and django-social-auth is. As for your question, I was quite unsure which to chose, so I did a lot of reading and asked on this forum. People recommended B), however I haven't fully understood why. Intuitively I would have chosen A) by myself, not only because it was shown in the online tutorial I read (Tango with Django) but also because it seems to be less complex. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/39c66976-7cbd-4dd3-aa96-05ba436bbae7%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Which 3rd Party (Social) Auth App should I use?
I'm trying to integrate Social Auth to my Webapp. As I have to store a lot of additional information for each User I had two choices: A) Create a UserProfile with a OneToOne Relationship to User B) Overwrite the default User class by inhereting from Abstract User Currently I chose to go with B) as was also recommended. Now I have found three Addons that seem to be popular: - django-registration-redux - django social-auth - django-allauth I found some tutorial for all three of those (can post links to them if anyone wants) however, all tutorial just make use a regular user model. I have not been able to find a solution / example on how to connect to a custom UserProfile for example. I have tested django-allauth using my overwritten User Model and I was able to log in using Facebook, however I have no idea how to automatically include my custom properties in a sign-up form (as there is essentially no sign up, just log in via facebook). What I'd like to do is the following: - Allow users to register at my site - During registration not only ask for username, email and password but additional required fields like language settings (so extend default form) - Allow Sign-Up / Login through OAuth (Facebook and Google at least) but still have the user fill out those required fields. Can someone please tell me which 3rd Party App to use and maybe point me to a tutorial / example that adds additional user properties during registration? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/27571248-a38a-4c08-890d-273146444953%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Many-To-Many Relationship changes not accessible in Model.save() ?
Thanks for the links. It might be related to that bug. In my scripts I added another save() and then it works of course and as for the Admin Panel, until I have a solution I put a message into the help text that users have to click 'save and continue' first and then 'save' afterwards. Then it's fine as well. Phew at least the workaround was quickly implemented, still I spend at least 1 hour on figuring out what's going wrong. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ef541b28-43c1-4a4a-a85d-466e76e3e381%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Many-To-Many Relationship changes not accessible in Model.save() ?
I'm trying to access the value of a many-to-many relationship during the save() method of my model but it always returns the state it had before, even though the first thing I do is call super.save(). class Database(models.Model): ... questions = models.ManyToManyField(Question) pathToAudioFiles = models.CharField(max_length=255, unique=True, help_text="Please type in path to folder with Audio Files, e.g. media/database1/*.mp3", verbose_name="Path to Audio Files") def audioData(self): return AudioData.objects.filter(database=self.pk) def __unicode__(self): return self.name def save(self, *args, **kwargs): super(Database, self).save(*args, **kwargs) filelist = glob.glob(self.pathToAudioFiles) for file in filelist: print "adding file %s" % file audioData = AudioData.objects.get_or_create(path=file, filename= file, database=self) # then update pairs for a in self.audioData(): print 'working on %s' % a print self.questions.all() for q in self.questions.all(): print "creating pairs with %s" % q pair = AudioQuestionPair.objects.get_or_create(audioData=a, question=q, database=self) for choice in q.choices: print "adding answer %s" % choice answer = Answers.objects.get_or_create(body=choice, audioQuestionPair=pair) In this case, the idea is that the Admin can add a new 'database' (they wanted to call it that way), that contains some audio files that are stored somewhere on disk. so far so good. Later on, using the Django Admin Panel the admin modifies the questions. When I use the shell I get this output, which is normal: >>> from play.models import * >>> db = Database.objects.create(name="database1", pathToAudioFiles= "media/database1/*.mp3") adding file media/database1\devel_001.mp3 adding file media/database1\devel_010.mp3 working on media/database1\devel_001.mp3 [] working on media/database1\devel_010.mp3 [] Then I go to the Admin Panel and edit the associated questions of that object, and when I hit save: [12/Jan/2015 21:57:50] "GET /admin/play/database/1/ HTTP/1.1" 200 7021 [12/Jan/2015 21:57:50] "GET /admin/jsi18n/ HTTP/1.1" 200 2372 adding file media/database1\devel_001.mp3 adding file media/database1\devel_010.mp3 working on media/database1\devel_001.mp3 [] working on media/database1\devel_010.mp3 [] [12/Jan/2015 21:57:56] "POST /admin/play/database/1/ HTTP/1.1" 302 0 So even though I did change the associations it's not accessible during the save method. It still turns up empty. How can I solve this? After hitting save I need to be able to process self.questions.all() right away. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/16f1653a-764c-4163-9c13-c661513d9321%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Django modify model instance from HTML
Thanks for the answer. I will implement an AJAX call to another url / view than. This I should be able to figure out using a Button and Google. The URL can be anything like /settings/autoplay/. The view just has to update the property (user object should be in the request already). However, what should the view return? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/40792af2-c49c-4a65-9635-2f190b3f4a61%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Django modify model instance from HTML
I want to know if it is possible to directly modify and save a model instance in the HTML Template and not via a view and extra URL. My user has a Boolean Property, I want to display it as a toggle button on the website and the user should be able to toggle it on or off without leaving the website or reloading it. class User(AbstractBaseUser, PermissionsMixin): ... autoplay_enabled = models.BooleanField(default=True) ... Is this possible without an extra view or form? Basically I just need to set request.user.autoplay_enabled = False (or True) and then *save()* it If I can't modify the object directly in the HTML template is it at least possible to just execute a function I have defined somewhere in my Python code, without having the need to create a new view? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/abed6766-0bb5-40d9-a2b3-065e17633937%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Question on Template placement in file system
I have been working through the official Django 1.7 tutorial and also Tango with Django but I'm confused as to where put my templates - I want to follow best practices as much as possible. Now currently I only plan to develop a single project with a single app, but I might want to include 3rd party apps later on. So I have created my project and started a new app inside. Since all pages should use the same html template I wanted to place the base.html into the project template folder. Or should I still put everything into the app/template folder? Suggestion A) project_dir/templates/base.html project_dir/templates/app/index.html (extends base.html) Suggestion B) project_dir/app_dir/templates/base.html project_dir/app_dir/templates/index.html Suggestion C) (as in the tutorial) project_dir/app_dir/templates/base.html project_dir/app_dir/templates/app/index.html Later on when somebody goes to my website I want to show him some stuff from my app on the index page already. So on http://mysite.com/ there should already be content from my app, but there will also be static html files like 'contact', 'impress', 'help' and so on, which I wanted to put somewhere in my project folder and not within the app. But everything should rely on the same base.html template so all pages use the same javascript & css files. Is there maybe another good tutorial for this available? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b28eb626-ebd9-4db0-9130-a973ce28f324%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Changes to Model does not migrate to sqlite with Django 1.7?
Hi, I'm afraid I don't have them. Apparently after deleting my database file and then just running manage.py makemigrations, it deleted the old migration files and started anew. Right now I'm also unable to re-produce it on purpose :( But it happened a couple of times for me since I regularly make multiple changes to my model (I'm still at the beginning of development) but if I just add a single new field now it works as expected. Maybe sometimes Django can't detect changes to my file because I store my project in my dropbox folder and maybe this might be messing it up? On Monday, December 8, 2014 1:04:37 PM UTC+1, Markus Holtermann wrote: > > I tried to reproduce the problem with the steps you explained, but it > works fine for me. Can you post your existing migration files for that app > too, please. This will then hopefully give us some hints to solve your > problem. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/530b0a83-e651-45b7-9b39-1169acc0a979%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Changes to Model does not migrate to sqlite with Django 1.7?
Yes of course. Like I said, when I run into this error I have to delete my database file and do a fresh migration anyway. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/84327fd5-0381-4ed9-af32-913db71c4544%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Changes to Model does not migrate to sqlite with Django 1.7?
Well, I did follow some best-practice guides and even asked here on the forums on how to model my User class. I want the users to be able to use their username or email as login, and going with this inheriting from AbstractBaseUser and PermissionsMixin is what I was told. Maybe this doesn't work for 1.7 anymore? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a0ba54c5-1589-44a0-9705-1ffd0f0cf0b2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Changes to Model does not migrate to sqlite with Django 1.7?
Ok, here is part of the User Model: class User(AbstractBaseUser, PermissionsMixin): SEX = ( ('m', 'male'), ('f', 'female') ) RANG = ( ('b', 'beginner'), ('e', 'expert'), ('m', 'master') ) username = models.CharField(_('username'), max_length=30, unique=True, help_text=_('Required. 30 characters or fewer. Letters, numbers and @/./+/-/_ characters'), validators=[ validators.RegexValidator(re.compile( '^[\w.@+-]+$'), _('Enter a valid username.'), _('invalid')) ]) first_name = models.CharField(_('first name'), max_length=30, blank=True , null=True) last_name = models.CharField(_('last name'), max_length=30, blank=True, null=True) email = models.EmailField(_('email address'), max_length=255, unique= True) is_staff = models.BooleanField(_('staff status'), default=False, help_text=_('Designates whether the user can log into this admin site.')) is_active = models.BooleanField(_('active'), default=True, help_text=_('Designates whether this user should be treated as active. Unselect this instead of deleting accounts.')) date_joined = models.DateTimeField(_('date joined'), default=timezone. now) expires = models.DateTimeField(_('expiration date'), default= one_year_from_now) age = models.IntegerField(blank=True, null=True) sex = models.CharField(max_length=1, choices=SEX, blank=True) native_language = models.CharField(max_length=200, blank=True) english_proficiency = models.CharField(max_length=100, blank=True) audio_device = models.CharField(max_length=200, blank=True) autoplay_enabled = models.BooleanField(default=True) USERNAME_FIELD = 'username' REQUIRED_FIELDS = ['email', ] objects = UserManager() class Meta: verbose_name = _('user') verbose_name_plural = _('users') def get_full_name(self): full_name = '%s %s' % (self.first_name, self.last_name) return full_name.strip() def get_short_name(self): return self.first_name """ def is_active(self): return timezone.now() <= self.expires """ def email_user(self, subject, message, from_email=None): send_mail(subject, message, from_email, [self.email]) (I removed some unrelated fields). Now what I did was add the autoplay_enabled feature yesterday which wasn't there before. After adding this field, I saved the models.py ran manage.py makemigrations (no changes detected) and then still tried to run manage.py migrate. After starting the server when I tried to log into the Admin panel with the Admin user (the DB was already populated by the Admin user, two more users and other stuff) it gave me an OperationalError: column autoplay_enabled does not exist. This happened to me a lot of times when I added new fields to any of the models. I ended up writing a script that pre-populates the DB for me but I still have to manually delete my sqlite file, run migrations or syncdb and then create the superuser again. So what am I doing wrong? I'm sure it's just my fault. At first I even manually edited the migrations file in the past, for example when I changed one of the fields to be mandatory instead of being optional. Old data in the database had this field still set to null, and sometimes Django asked me what to do with it but most of the time I never got it to work correctly - so again delete DB and repeat. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/01706dc6-ea01-4d1d-ab3a-692f17435ddc%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Changes to Model does not migrate to sqlite with Django 1.7?
Hi, I'm having trouble with changes to my Models. I just added a couple of new fields to my existing models but when I run manage makemigrations it says: No changes detected. When I try to log in to the admin panel it gives an operational error and says: No such column (because I added a column to my user model). I have tried to get rid of this error using google and various calls to makemigrations app_name or syncdb or whatever, but nothing helps. I always have to delete my sqlite database file and start with a new DB. Is this a limitation of sqlite or some bug in Django? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/59e7284e-cdf0-44f4-a565-d8ce271776a6%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Extending, inheriting User Model or custom User Model?
Dear Daniel and Carl, thanks for your advice. However I'm a bit confused now. So in general you recommend that I follow the guide for substituting my own custom model but at the same time Carl is warning me that overwriting AUTH_USER_MODEL is quite painful for an existing application (right now I haven't really done much except basic Models and some Views and Forms), but as I read the guide that is exactly what I have to do when using my own custom Model. I will still try to get it to work somehow. Are all the tutorials found on the internet for Django 1.5 still valid with 1.7? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b07fd60f-ae16-4f51-8cb7-dcabd53d12f1%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Extending, inheriting User Model or custom User Model?
I'm trying to figure out how to create my Custom User Model. In the official docs I basically found two different strategies: Extending User Model or Custom User Model: https://docs.djangoproject.com/en/1.7/topics/auth/customizing/#extending-the-existing-user-model Extending means I have a OnetoOne Relationship to the User Table in my own UserProfile Model, whereas the other method inherits from AbstractBaseUser and looks quite complicated with a lot of warnings that I can't not change this easily after I created my database. I want to design a web app where users can log in and once log in take some kind of surveys. For this I want to make use of Django's Authentication methods, so only registered and logged in Users can take part in the survey. However I want to save additional data for each User in the database, like Age, Country, Score and so on. In the Admin interface it would be great if I could just select a User Entry and see all fields, the default from the User Model plus my added fields. It might be a good idea to use OAuth later on as well, to be able to have users authenticate through Facebook and so on, however that is not required right now (I did create quick test project for the social auth plugin and it worked). Still I don't really understand the differences between those two methods and google didn't help me because most tutorials show either route but never say why one is better than the other. So which should I use in my case? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bba38b2f-5924-495d-9043-a33ed52a4ec2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Beginner needs help with models.py for a Survey like Website
Hi all, I need to create some kind of survey for my studies but I'm struggling with the models.py. I did read some tutorial on Django and I like it very much, but I'm no expert when it comes to database modellling. Here is my proposed models.py: class User(models.Model): SEX = ( ('m','male'), ('f','female') ) user_name = models.CharField(max_length=200) user_age = models.IntegerField() user_sex = models.CharField(max_length=1, choices=SEX) user_count_answers_given = models.IntegerField(default=0) def __unicode__(self): return self.user_name # a Collection of Pictures # a subset of Questions is chosen for each Collection class Collection(models.Model): collection_name = models.CharField(max_length=200) def __unicode__(self): return self.collection_name # an Picture is place into exactly one Collection class Picture(models.Model): path = models.CharField(max_length=500) title = models.CharField(max_length=200) def __unicode__(self): return self.title # a List of Questions like: # - How much do you like this Picture? # - Is there a girl or a boy in the Picture? class Question(models.Model): question_text = models.CharField(max_length=200) collection_enabled = models.ManyToManyField(Collection) def __unicode__(self): return self.question_text # Have to save each answer for a specific Picture # by a specific user and for a specific question class Answer(models.Model): question = models.ForeignKey(Question) User = models.ForeignKey(User) Picture = models.ForeignKey(Picture) choice_value = models.IntegerField() timestamp = models.DateField(datetime.now()) Now the problem I have is with the Answer class in general. I want to create several Collections consisting of different pictures. Also I will have a list of questions. Not all questions should be enabled for each Collection, for example if I create a collection of pictures with no persons in the pictures, it doesn't make sense to ask the user if they see a girl or a boy in the picture. That is why I added this ManyToMany relationship in Question. I'm not sure if this is the correct way to do this. Let's assume that I enabled 3 Questions for a certain Collection of Pictures. Now I want to track the answers given by the Users. For some questions the answer should be select by a button labeled 'boy' or 'girl' whereas for likeability it should be selected using a radio button which ranges from 0 (don't like) to 7 (like it very much). Later on, I need to be able to see for each picture how many people selected which answer (10 people selected boy, 5 people girl and so on). Also I want to calculate an average score for likeability. I want to display this score directly after the user gave his input. So I thought that I need additional fields in the Picture class to safe the average score, but what if my question list changes? Then I need to update the Picture class every time and add an additional field for each new question. That doesn't make sense. I would need something like a Decorator pattern - but I have no idea if this is possible in databases, or how to model it. Can anyone please help me with this? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ddb89b0f-cc52-4696-a2c4-8b76fc7e917f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Can Django be used to create a survey website?
I need to create a survey like website. Users should be able to register and then are presented with different images which they are asked questions about. So essentially I have multiple Sets of Images, a set of questions (not all questions are valid for all sets of images) and a set of answers. Answers can be either pre-filled strings (for example question about gender: male / female) or an int value from 0 to 7. Later on I need to figure out who gave which answers for which image and I need to count all answers for a specific question and image combination to calculate how many people voted for male for example and give an average number as result for other questions. Is this possible to create with Django? So far I did do the tutorial and tried creating my own models and some basic views but I'm having some trouble with my model already. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/740700e9-2206-4e9f-8cb0-42e7096677fe%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.