Code

Opened 9 years ago

Closed 9 years ago

Last modified 7 years ago

#94 closed defect (fixed)

Mysterious error

Reported by: Joey Marshall Owned by: adrian
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I am trying to create a module for news, but with the code below, it reports a mysterious error.
When trying to add a news item, it says "Please correct the errors below.", but it doesn't show any like it normally does. :/ I'm thinking it's just a stupid mistake on my part as I'm new to this (oh, I guess pretty much every one is right now ;) ) and rather new to python programming (and I've done little with object oriented coding).

So if someone could help me out, that would be great!

# 'news' module code:

from django.core import meta
from django.models import auth, core

# Create your models here.

class News(meta.Model):
    fields = (
        meta.ForeignKey(auth.User, raw_id_admin=True),
        meta.CharField('title', maxlength=200),
        meta.DateTimeField('pub_date', 'date published'),
 meta.TextField('body',),
 meta.ManyToManyField(auth.Group, blank=True, help_text="Select which user groups will see this news article."),
    )
    
    admin = meta.Admin(
        fields = (
            (None, {'fields': ('title','body')}),
            ('Date information', {'fields': ('pub_date',)}),
     ('Groups', {'fields': ('groups',)}),
        ),
        list_display = ('title', 'pub_date', 'groups', 'was_published_today'),
        list_filter = ('pub_date', ),
        search_fields = ('title', ),
        date_hierarchy = 'pub_date',
    )
    
    
    def __repr__(self):
        return self.title
        
    def was_published_today(self):
        if self.pub_date.date() == datetime.date.today():
            return "Yes"
        else:
            return "No"
    was_published_today.short_description = 'Was published today'

Attachments (0)

Change History (2)

comment:1 Changed 9 years ago by Joey Marshall

oops, In that code there are some tabs insted of 4 spaces.

comment:2 Changed 9 years ago by anonymous

  • Resolution set to fixed
  • Status changed from new to closed

ok, I found out what was wrong. It wanted a user id.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.