This is probably a very newbie question however I'm kind of stuck.

I've been looking around for a way to render a user based view for a calendar scheduler however I can't seem to find anything about user-based views in django. It's probably really simple but I'm too blind to spot any documentation about it. Something alongside of a user profile.

I've read through the django book but I cannot recall if there was anything that describes what I'm trying to achieve. Any hints or links would be a great help.

Thank you.

有帮助吗?

解决方案

What you are actually are looking for is a DetailView, Django nowdays uses Class Based Views which are kind of self explanatory, there is a ListView which is used to display a list of objects, a DetailView which is used to display details of a specific object and others like FormViews, CreateView, DeleteView etc (you can find more information to this very detailed site apart from Django's own documentation): http://ccbv.co.uk/

Since you want to display a view for a specified object, this becomes a DetailView, since a User also has a calendar with events, then you also need to fetch the Calendar with the events (but this all breaks down to how your model relations are glued together). For instance if your user has a Single Calendar (he...should actually) and many events in the calendar, you could declare a Queryset in the DetailView: http://ccbv.co.uk/projects/Django/1.6/django.views.generic.detail/DetailView/

其他提示

You can create common template for all users and then populate it with user specific data.

I'm not really sure where you're stuck, or what you're defining as a "user-based view".

The user model is like any other: you can query it, and other models can be related to it. If you just want to show data for the current user, you get that from request.user: otherwise, you can pass the user ID in the URL like any other parameter.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top