0

i am working on a calendar application.i am facing following error on my web page .this is my views.py .can someone please help me in it. Thanks in advance

views.py

from __future__ import unicode_literals
from django.shortcuts import render
from events.models import Event
import datetime
import calendar
from django.urls import reverse
from django.utils.safestring import mark_safe
from events.utils import EventCalendar
# Register your models here.

class EventView(Event):
    list_display = ['day', 'start_time', 'end_time', 'notes']
    change_list_template = 'admin/events/change_list.html'

    def changelist_view(self, request, extra_context=None):
        after_day = request.GET.get('day__gte', None)
        extra_context = extra_context or {}

        if not after_day:
            d = datetime.date.today()
        else:
            try:
                split_after_day = after_day.split('-')
                d = datetime.date(year=int(split_after_day[0]), month=int(split_after_day[1]), day=1)
            except:
                d = datetime.date.today()

        previous_month = datetime.date(year=d.year, month=d.month, day=1)  # find first day of current month
        previous_month = previous_month - datetime.timedelta(days=1)  # backs up a single day
        previous_month = datetime.date(year=previous_month.year, month=previous_month.month,
                                       day=1)  # find first day of previous month

        last_day = calendar.monthrange(d.year, d.month)
        next_month = datetime.date(year=d.year, month=d.month, day=last_day[1])  # find last day of current month
        next_month = next_month + datetime.timedelta(days=1)  # forward a single day
        next_month = datetime.date(year=next_month.year, month=next_month.month,
                                   day=1)  # find first day of next month

        extra_context['previous_month'] = reverse('admin:events_event_changelist') + '?day__gte=' + str(
            previous_month)
        extra_context['next_month'] = reverse('admin:events_event_changelist') + '?day__gte=' + str(next_month)

        cal = EventCalendar()
        html_calendar = cal.formatmonth(d.year, d.month, withyear=True)
        html_calendar = html_calendar.replace('<td ', '<td  width="150" height="150"')
        extra_context['calendar'] = mark_safe(html_calendar)
        return super(EventAdmin, self).changelist_view(request, extra_context)

this is the error in my terminal

Traceback (most recent call last): File "C:\Users\vikas visking\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\handlers\exception.p y", line 35, in inner response = get_response(request) File "C:\Users\vikas visking\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\deprecation.py", li ne 97, in call response = self.process_response(request, response) File "C:\Users\vikas visking\AppData\Local\Programs\Python\Python36\lib\site-packages\django\middleware\clickjacking.p y", line 26, in process_response if response.get('X-Frame-Options') is not None: AttributeError: 'EventView' object has no attribute 'get' [18/Apr/2018 21:23:56] "GET /events/ HTTP/1.1" 500 56977

2 Answers 2

1

It looks as if you are trying to create a custom model admin. In that case, you should be subclassing admin.ModelAdmin.

from django.contrib import admin

class EventAdmin(admin.ModelAdmin):
    list_display = ['day', 'start_time', 'end_time', 'notes']
    change_list_template = 'admin/events/change_list.html'

admin.site.register(Event, EventAdmin)

This code belongs in your admin.py, not your views.

Sign up to request clarification or add additional context in comments.

4 Comments

Yes sir this code belongs to admin.py but i am trying to make a custom views for users in views.py
If you're writing views then I wouldn't start with model admin code. It's not very re-usable.
I know sir thats why i need ur help. I want to make the same module for users what should i do..thanks in advance sir you replied
I can't convert that code to a normal view for you. I suggest you start with the simplest view possible, and begin to add functionality to it. When you get stuck, then ask a new question.
0

Try:

from django.views.generic import ListView
class EventView(ListView):
    model = Event

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.