initial commit
This commit is contained in:
32
apps/blog/resources.py
Normal file
32
apps/blog/resources.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from import_export import resources, fields
|
||||
from import_export.widgets import ForeignKeyWidget, ManyToManyWidget
|
||||
|
||||
from apps.users.models import User
|
||||
from apps.blog.models import Post, Category, Tag
|
||||
|
||||
class CategoryResource(resources.ModelResource):
|
||||
class Meta:
|
||||
model = Category
|
||||
fields = ('id', 'name', 'slug', 'description', 'created_at')
|
||||
|
||||
class PostResource(resources.ModelResource):
|
||||
author = fields.Field(
|
||||
column_name='author',
|
||||
attribute='author',
|
||||
widget=ForeignKeyWidget(User, 'username')
|
||||
)
|
||||
category = fields.Field(
|
||||
column_name='category',
|
||||
attribute='category',
|
||||
widget=ForeignKeyWidget(Category, 'name')
|
||||
)
|
||||
tags = fields.Field(
|
||||
column_name='tags',
|
||||
attribute='tags',
|
||||
widget=ManyToManyWidget(Tag, field='name', separator='|')
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = Post
|
||||
fields = ('id', 'title', 'slug', 'content', 'excerpt', 'author',
|
||||
'category', 'tags', 'status', 'is_featured', 'published_at', 'created_at')
|
||||
Reference in New Issue
Block a user