Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added some advanced futures for admin.py in admin panel such as search field displ… #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 0 additions & 128 deletions bestoon/settings.py.sample

This file was deleted.

29 changes: 25 additions & 4 deletions web/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
from django.contrib import admin
from .models import Expense, Income, Token, News
# Register your models here.
class NewsAdmin(admin.ModelAdmin):
list_display = ('title', 'date',)
list_filter = ('date',)
search_fields = ('title', 'text',)
class Meta:
model = News
class TokenAdmin(admin.ModelAdmin):
search_fields = ('user',)
class Meta:
model = Token
class IncomeAdmin(admin.ModelAdmin):
list_display = ('user', 'amount',)
list_filter = ('date',)
search_fields = ('title', 'text','amount',)
class Meta:
model = Income
class ExpenseAdmin(admin.ModelAdmin):
list_filter = ('date',)
search_fields = ('text', 'user','amount',)
class Meta:
model = Expense

admin.site.register(Expense)
admin.site.register(Income)
admin.site.register(Token)
admin.site.register(News)
admin.site.register(Expense,ExpenseAdmin)
admin.site.register(Income, IncomeAdmin)
admin.site.register(Token, TokenAdmin)
admin.site.register(News, NewsAdmin)
7 changes: 5 additions & 2 deletions web/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class News(models.Model):
title = models.CharField(max_length=250)
text = models.TextField()
date = models.DateTimeField()
class Meta:
verbose_name='News'
verbose_name_plural='News'
def __unicode__(self):
return self.title

Expand All @@ -32,7 +35,7 @@ class Expense(models.Model):
text = models.CharField(max_length=255)
date = models.DateTimeField()
amount = models.BigIntegerField()
user = models.ForeignKey(User)
user = models.ForeignKey(User, on_delete=models.CASCADE)

def __unicode__(self):
return "{}-{}-{}".format(self.date, self.user, self.amount)
Expand All @@ -42,7 +45,7 @@ class Income(models.Model):
text = models.CharField(max_length=255)
date = models.DateTimeField()
amount = models.BigIntegerField()
user = models.ForeignKey(User)
user = models.ForeignKey(User, on_delete=models.CASCADE)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also fixed some bugs with ForeignKey it showed error that on_delete attribute has to be defiend

def __unicode__(self):
return "{}-{}-{}".format(self.date, self.user, self.amount)