Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8264389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:26:28+00:00 2026-06-08T04:26:28+00:00

I have a model and a manager as class PlaylistManager(models.Manager): def add_playlist(self, name): playlist

  • 0

I have a model and a manager as

class PlaylistManager(models.Manager):
    def add_playlist(self, name):
        playlist = self.model(name)
        playlist.save()
        return playlist

class Playlist(models.Model):
    name = models.CharField(max_length=30)
    date_created = models.DateTimeField(auto_now_add=True)
    date_modified = models.DateTimeField(auto_now=True)
    deleted = models.BooleanField(default=False)
    objects = PlaylistManager() # is a customer manager

    class Meta:
        db_table = 'playlists'

Then I write a test to make sure this works

from django.test import TestCase
from models import Playlist

"""
The idea is that each call to create playlist will make a new playlist

"""

PLAYLIST = 'playlist'
class PlaylistTest(TestCase):
    def insert_playlist(playlist=PLAYLIST):
        Playlist.objects.add_playlist(playlist)

    def test_add_one_video_to_playlist(self):
        self.insert_playlist()
        self.assertEqual(Playlist.objects.count(), 0, msg='playlist count is not 1, it is ' + str(Playlist.objects.count()))

When I run this test from command-line I see the following error

$ python manage.py test playlists --settings=myApp.settings.dev
Creating test database for alias 'default'...
EE
======================================================================
ERROR: test_add_one_video_to_playlist (myApp.apps.playlists.tests.PlaylistTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/me/code/p/myApp/myApp/apps/playlists/tests.py", line 15, in test_add_one_video_to_playlist
    self.insert_playlist()
  File "/Users/me/code/p/myApp/myApp/apps/playlists/tests.py", line 12, in insert_playlist
    Playlist.objects.add_playlist(playlist)
  File "/Users/me/code/p/myApp/myApp/apps/playlists/models.py", line 8, in add_playlist
    playlist.save()
  File "/Users/me/code/p/virtualenv/myApp/lib/python2.7/site-packages/django/db/models/base.py", line 463, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "/Users/me/code/p/virtualenv/myApp/lib/python2.7/site-packages/django/db/models/base.py", line 524, in save_base
    manager.using(using).filter(pk=pk_val).exists())):
  File "/Users/me/code/p/virtualenv/myApp/lib/python2.7/site-packages/django/db/models/query.py", line 621, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "/Users/me/code/p/virtualenv/myApp/lib/python2.7/site-packages/django/db/models/query.py", line 639, in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File "/Users/me/code/p/virtualenv/myApp/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1250, in add_q
    can_reuse=used_aliases, force_having=force_having)
  File "/Users/me/code/p/virtualenv/myApp/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1099, in add_filter
    value = value()
  File "/Users/me/code/p/virtualenv/myApp/lib/python2.7/site-packages/django/test/testcases.py", line 512, in __call__
    result.addError(self, sys.exc_info())
AttributeError: 'NoneType' object has no attribute 'addError'

======================================================================
ERROR: test_add_one_video_to_playlist (myApp.apps.playlists.tests.PlaylistTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/me/code/p/virtualenv/myApp/lib/python2.7/site-packages/django/test/testcases.py", line 508, in __call__
    self._post_teardown()
  File "/Users/me/code/p/virtualenv/myApp/lib/python2.7/site-packages/django/test/testcases.py", line 522, in _post_teardown
    self._fixture_teardown()
  File "/Users/me/code/p/virtualenv/myApp/lib/python2.7/site-packages/django/test/testcases.py", line 847, in _fixture_teardown
    transaction.leave_transaction_management(using=db)
  File "/Users/me/code/p/virtualenv/myApp/lib/python2.7/site-packages/django/db/transaction.py", line 52, in leave_transaction_management
    connection.leave_transaction_management()
  File "/Users/me/code/p/virtualenv/myApp/lib/python2.7/site-packages/django/db/backends/__init__.py", line 115, in leave_transaction_management
    raise TransactionManagementError("This code isn't under transaction "
TransactionManagementError: This code isn't under transaction management

----------------------------------------------------------------------
Ran 1 test in 0.102s

FAILED (errors=2)
Destroying test database for alias 'default'...

I don’t know what is happening here. All I know that I have a Transaction Management Middleware as

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # -- db transaction management -- #
    'django.middleware.cache.UpdateCacheMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.transaction.TransactionMiddleware',
    'django.middleware.cache.FetchFromCacheMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

which I plan to use in my views.py functions as

@transaction.commit_on_success
def addPlaylist(name):
    """
    adds playlist
    """
    pass

But currently none of the views functions are called

Please help me what is going on here

Thank you

UPDATE

I am using Django 1.4

09:28:21  $ python
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(1, 4, 0, 'final', 0)
>>> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T04:26:30+00:00Added an answer on June 8, 2026 at 4:26 am

    After Changing my PlaylistManager to following, things started to work

    class PlaylistManager(models.Manager):
        def add_playlist(self, name):
            playlist = Playlist(name=name) # this line changed
            playlist.save()
            return playlist
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class as class PlaylistManager(models.Manager): def add_playlist(self, name): playlist = Playlist(name=name) playlist.save()
I have a memoized Django model manager method as follows: class GroupManager(models.Manager): def get_for_user(self,
I have two models: class Product(models.Model): name = models.CharField(max_length=255) class ProductPhoto(models.Model): product = models.ForeignKey('Product',
I have two models like so: class Visit(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length=65535,
I have the following model: class UptimeManager(models.Manager): def with_length(self): Get querySet of uptimes sorted
I have 2 model: class Sideshow_manager(models.Model): url_id = models.CharField(max_length=250,editable=False,unique=True) title = models.CharField(max_length=250) date =
Imagine, I have News models with many text fields class News(models.Model): title = models.CharField(max_length=255)
I have the following model: class CompanyReport(models.Model): company = models.CharField(max_length=300) desc = models.TextField() text
I have the following: MODEL.PY LIST = (('Manager', 'Manager'),('Non-Manager', 'Non-Manager'),) class Employee(models.Model): fname =
I have the following in my models.py: class HostData(models.Model): Manager = models.ForeignKey(Managers) Host =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.