Python models 模块,Category() 实例源码

我们从Python开源项目中,提取了以下15个代码示例,用于说明如何使用models.Category()

项目:eventbrite    作者:saurabhjinturkar    | 项目源码 | 文件源码
def fetch_categories(self):
        """
        Fetch categories present on EventBrite.

        If categories are not cached into database, they are accessed from API and stored into database.
        Returns:

        """
        global categories_stored
        if not categories_stored:
            data = Category.objects.all().delete()
            payload = {'token': self.token}
            request = requests.get(self.base_url + 'categories', params=payload)
            data = request.json()
            for category in data['categories']:
                c = Category()
                c.name = category['name']
                c.name_localized = category['name_localized']
                c.category_id = category['id']
                c.save()
            categories_stored = True

        data = Category.objects.all()
        return data
项目:bc-7-Todo-Console-Application    作者:Onikah    | 项目源码 | 文件源码
def upload_firebase(self):
        data={}
        category = []
        cat = session.query(Category).all()
        for x in cat:
            qry = session.query(Items).filter(Items.category_id==x.id)
            data[x.category]=[d.items for d in qry]

        name = click.prompt(click.style('Please enter your username:',  fg='cyan', bold=True))
        print Fore.GREEN  + 'Syncing..... '
        jsonData = firebase.put( '/todo-cli', name, data)
        if jsonData:
            print Fore.CYAN + 'Done!'
            exit()
        else:
            print 'Try again'
项目:bc-7-Todo-Console-Application    作者:Onikah    | 项目源码 | 文件源码
def get_firebase(self):
        name = click.prompt(click.style('Please enter username?', fg = 'cyan' , bold=True))
        jsonData = firebase.get('/todo-cli' , name)
        for k in jsonData:
            #inserting category to database
            category = Category(category=k)
            session.add(category)
            session.commit()

            for i in jsonData[k]:
                s = select([Category])
                result = s.execute()
                for r in result:
                    if r[1] == k:
                        data = Items(category_id=r[0], items=i)
                        session.add(data)
                        session.commit()
                        session.close()

        click.secho('Done', fg = 'yellow' , bold=True)
项目:bc-7-Todo-Console-Application    作者:Onikah    | 项目源码 | 文件源码
def open_todo(name):


    os.system('clear')

    todo_title()

    s = select([Category])
    result = s.execute()
    for r in result:
        if r[1] == name:
            q = session.query(Items).filter(Items.category_id==r[0]).all()
            click.secho(name.upper(), fg='cyan', bold=True, underline=True)
            for i in q:
                click.secho('>>>' + i.items, fg='white', bold=True )
        # else:
        #   click.secho('oops list {} doesnt exist'.format(name), fg='white', bold=True )

    item = click.prompt(click.style('>>',  fg='green', bold=True))
    if item == 'done':
        list_todo(name) 
    else:           
        add_todo(name, item)
项目:plugin.audio.tidal2    作者:arnesongit    | 项目源码 | 文件源码
def _parse_category(self, json_obj):
        return Category(**json_obj)
项目:catherine    作者:felipemfp    | 项目源码 | 文件源码
def post(self, username):
        user = self.authenticate()
        if user:
            supposed_category = request.get_json(force=True)
            category = Category()
            category.category_id = next_id(user)
            category.user_id = user.user_id
            category.name = supposed_category['name']
            category.icon = supposed_category['icon']
            db.session.add(category)
            db.session.commit()
            if category.category_id:
                return json.jsonify(category.as_dict())
        raise InvalidUsage()
项目:eventbrite    作者:saurabhjinturkar    | 项目源码 | 文件源码
def setUp(self):
        c = Category()
        c.name = 'test_category'
        c.category_id = 1
        c.save()
项目:eventbrite    作者:saurabhjinturkar    | 项目源码 | 文件源码
def test_categories(self):
        test = Category.objects.get(pk=1)
        assert test.category_id, 1
项目:bc-7-Todo-Console-Application    作者:Onikah    | 项目源码 | 文件源码
def create_todo(name):


    os.system('clear')

    todo_title()
    cat = name


    category = Category(category=cat)
    session.add(category)
    session.commit()
    click.secho('{} Successfully added to categories add items'.format(cat), fg ='cyan', bold = True)

    open_todo(name)
项目:bc-7-Todo-Console-Application    作者:Onikah    | 项目源码 | 文件源码
def add_todo(name, item):

    os.system('clear')

    todo_title()

    s = select([Category])
    result = s.execute()
    for r in result:
        if r[1] == name:
            data = Items(category_id=r[0], items=item)
            session.add(data)
            session.commit()
            open_todo(name)
项目:bc-7-Todo-Console-Application    作者:Onikah    | 项目源码 | 文件源码
def list_todos_all():

    os.system('clear')

    todo_title()

    count = 1
    click.echo(click.style('TO DO LIST',  fg='green', bold=True , underline=True))
    s = select([Category])
    result = s.execute()
    if result:
        for row in result:
            q = session.query(Items).filter(Items.category_id==row[0]).all()

            click.echo(click.style( Fore.CYAN + str([count])+(Fore.CYAN + ' ' + row[1]),bold=True  ))
            count += 1


            for i in q:
                click.echo(click.style('>>>' + i.items  , fg='white', bold=True))

        start_todo()
    else:
        click.echo('Nothing to display')

#FIREBASE SYNC AND SAVE
项目:django-exercise    作者:wanzifa    | 项目源码 | 文件源码
def test_ensure_views_are_positive(self):
        cat = Category(name='test', views=-1, likes=0)
        cat.save()
        self.assertEqual((cat.views >= 0), True)
项目:django-exercise    作者:wanzifa    | 项目源码 | 文件源码
def test_slug_line_creation(self):
        cat = Category(name='Random Category String')
        cat.save()
        self.assertEqual(cat.slug, 'random-category-string')
项目:django-exercise    作者:wanzifa    | 项目源码 | 文件源码
def add_cat(name, views, likes):
    c = Category.objects.get_or_create(name=name)[0]
    c.views = views
    c.likes = likes
    c.save()
    return c
项目:django-exercise    作者:wanzifa    | 项目源码 | 文件源码
def test_ensure_first_and_last_visit(self):
        cat = Category(name='test', views=1, likes=0)
        cat.save()
        p = Page(title='xixi',category=cat)
        p.save()
        #response = self.client.get(reverse('add_page',kwargs={'catgory_slug_name':cat.slug}))
        response = self.client.get(reverse('goto'))
        first_visit = p.first_visit
        last_visit = p.last_visit
        self.assertEqual((first_visit < last_visit), True)