<commit_before>from tastypie.resources import ModelResource
from blog.models import Post, Comment
from tastypie.authorization import Authorization
from tastypie import fields<commit_msg>Create REST api<commit_after>from tastypie.resources import ModelResource
from blog.models import Post, Comment
from tastypie.authorization import Authorization
from tastypie import fields

class PostResource(ModelResource):
  author = fields.CharField(attribute="author")
  title = fields.CharField(attribute="title")
  text = fields.CharField(attribute="text")
  is_public = fields.BooleanField(attribute="is_public", use_in="detail")
  comments_list = fields.ToManyField('blog.api.CommentResource', "comment_set", related_name="post", null=True, use_in="detail")
  class Meta:
    queryset = Post.objects.all()
    resource_name = 'post'
    authorization = Authorization()
    always_return_data = True

class CommentResource(ModelResource):
  author = fields.CharField(attribute="author")
  text = fields.CharField(attribute="text")
  post = fields.ToOneField('blog.api.PostResource', 'post')
  class Meta:
    queryset = Comment.objects.all()
    resource_name = 'comment'
    authorization = Authorization()
    always_return_data = True
{'fraction_non_alphanumeric': 0.1008130081300813, 'fraction_numerical': 0.0, 'mean_word_length': 6.115606936416185, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5353347', 'n_tokens_mistral': 342, 'n_tokens_neox': 340, 'n_words': 81}