django-generic-views

Using class based generic view DetailView with a ModelForm reveals a bug - how to proceed?

邮差的信 提交于 2019-12-29 07:42:32
问题 I've been impressed how rapidly a functional website can go together with generic views in the tutorials. Also, the workflow for form processing is nice. I used the ModelForm helper class to create a form from a model I made and was delighted to see that so much functionality came together. When I used the generic list_detail.object_detail I was disappointed that all that I could display were fields individually. I knew the ModelForm class contained information for rendering, so I wanted to

Django: Display Generic ModelForm or predefined form

安稳与你 提交于 2019-12-22 18:19:52
问题 I have 3 models with various fields in each. For 2 of the models, I'm fine with using a generic form (through Django's create_object) to request data. I wrote a function that accepts the model name and sends the user to the generic form url(r'^add_(?P<modelname>\w+)/$', generic_add), def generic_add(request, modelname): mdlnm_model = models.get_model('catalog',modelname) return create_object(request, model = mdlnm_model, template_name = 'create.html', post_save_redirect = '/library/', extra

Django - Correct way to pass arguments to CBV decorators?

匆匆过客 提交于 2019-12-22 10:38:52
问题 The docs feature nice options for applying decorators such as login_required to Class Based Views. However, I'm a little unclear about how to pass specific arguments along with the decorator, in this case I'd like to change the login_url of the decorator. Something like the following, only valid: @login_required(login_url="Accounts:account_login") @user_passes_test(profile_check) class AccountSelectView(TemplateView): template_name='select_account_type.html' 回答1: You should use @method

Django IntegrityError at /new null value in column “owner_id” violates not-null constraint

南笙酒味 提交于 2019-12-22 08:14:08
问题 I'm trying to track the user that created an object using a CreateView and I'm doing it exactly like it's done in documentation (https://docs.djangoproject.com/en/dev/topics/class-based-views/generic-editing/, Models and request.user) except I don't use login_required() decorator but LoginRequiredMixin from django-braces instead. My model: class Contact(models.Model): owner = models.ForeignKey(User, editable=False) first_name = models.CharField(max_length=255,) last_name = models.CharField

How does one use a custom widget with a generic UpdateView without having to redefine the entire form?

时光总嘲笑我的痴心妄想 提交于 2019-12-21 07:59:08
问题 I have a model with a ManyToMany relation that I would like to update with a CheckBoxSelectMultiple widget while everything else uses the default generic form, but when I redefine that one form field, it is the only one that shows up in the UpdateView. Is there a way to use a widget with just one field without having to redefine the entire form? Views.py: from django.views.generic.edit import UpdateView from kunden.models import Kunde, Unternehmenstyp from kunden.forms import KundeEditForm

Django: How to login user directly after registration using generic CreateView

岁酱吖の 提交于 2019-12-17 23:42:07
问题 With django generic CreateView I can create a new user account, but how can I login this user automatically after registration using this technique? urls.py ... url( r'^signup/$', SignUpView.as_view(), name = 'user_signup' ), ... views.py class SignUpView ( CreateView ) : form_class = AccountCreationForm template_name = 'accounts/signup.html' success_url = reverse_lazy( 'home' ) forms.py class AccountCreationForm ( forms.ModelForm ) : def __init__( self, *args, **kwargs ) : super(

KeyError: 'manager' in django get_initial

被刻印的时光 ゝ 提交于 2019-12-13 03:33:10
问题 I working on FormView, and I need to set initial from another object, an example in my case we use Question model to set an initial for QuestionSuggestedEditsForm . But we got an error when updating the initial dict. 1. models.py @python_2_unicode_compatible class Question(TimeStampedModel): author = models.ForeignKey( User, related_name='question_author') title = models.CharField( _('Title'), max_length=200) slug = models.SlugField( _('Slug'), max_length=200, unique=True) tags = models

Django class based view pagination

随声附和 提交于 2019-12-12 04:23:16
问题 Hi i want to paginating queryset(lectures). and i tried. but it doesn'work how can i do? class tag_detail(View): def get(self, request, pk): tag_hit = get_object_or_404(TagModel, id=pk) tag_hit.view_cnt = tag_hit.view_cnt + 1 tag_hit.save() tag = TagModel.objects.get(id=pk) lectures_data = LectureModel.objects.filter(tags__id=pk).order_by('-id') paginator = Paginator(lectures_data, 2) page = request.GET.get('page') try: lectures = paginator.page(page) except PageNotAnInteger: lectures =

object_detail() got multiple values for keyword argument 'queryset' while inputting only one

自闭症网瘾萝莉.ら 提交于 2019-12-12 01:27:57
问题 from django.conf.urls.defaults import * from django.conf import settings from Website.Blog.models import Post # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() index = { 'queryset': Post.objects.all(), 'date_field': 'created_on', 'template_name': 'index.html', 'num_latest': 5 } post = { 'template_name': 'index.html', 'queryset': Post.objects.all(), # only here, what could be wrong? 'slug': 'slug', } urlpatterns = patterns('', # Example:

How to overwrite get method in generic RetrieveAPIView in django rest framework to filter the results

蹲街弑〆低调 提交于 2019-12-11 16:57:07
问题 I have an API that can list several buildings. Each building belongs to several building groups and each building group contains several buildings. I want to show single fields of one building group. More specifically I want to show all buildings of one building group in my RetrieveAPIView. I can list a single BuildingGroup instance using the generic view like so: class BuildingGroupRetrieveAPIView(RetrieveAPIView): serializer_class = BuildingGroupSerializer queryset = BuildingGroup.buildings