20067

Manager isn't accessible via (…) instances

Question:

I have two tables namely Stuff and Boss. Based on the slug(user_type) from the user, I define which table is going to be used.

def Person_info(request,user_type): if user_type=="Staff": item=Staff() elif user_type=="Boss": item=Boss() .................

Then, I need to get the last id for item from its table.

But, I am having "Manager isn't accessible via Staff instances" When I try to get the last id of Staff table.

How can I bypass this problem ?

Answer1:

You are querying using the instance, which is incorrect.

Change your code as below:

def Person_info(request,user_type): if user_type=="Staff": # Note no () at the end, which makes the item an instance by instantiating it, not a class by assigning it item=Staff elif user_type=="Boss": item=Boss ....

Recommend

  • post json to java server
  • How does Booking.com close their app programmatically?
  • Force VSProps settings to override project settings
  • mysql how to find the total number of child rows with respect to a parent
  • How to add a fadeIn effect while changing background image using .css in Jquery
  • PyInstaller Tkinter window low resolution in App bundle, but not in app program
  • remove user from group Mac Os X (El Capitan)
  • ORA-01843: not a valid month
  • Python: I fell in an infinite loop
  • Standard keys functions in curses module
  • Polymer paper-input and form submission
  • JavaScript overloading with a callback
  • PHP: Calling a private method from within a class dying badly
  • Regex for nested values
  • How do I shift the decimal place in Python?
  • Possible to “watch” both HAML and SASS at the same time?
  • How to specify input and output paths from cmd.exe for a PowerShell script?
  • Odoo 10 - Overriding unlink method
  • Grails calculated field in SQL
  • Alternative To body {overflow:scroll;} That Will Prevent Page Jostling/Wriggling?
  • Sencha Touch 2.0 Controller refs attribute not working?
  • Setting up SourceTree to merge unity3d scenes with UnityYAMLMerge
  • When to use `image` and when to use `Matrix` in Emgu CV?
  • What is the “return” in scheme?
  • Can Jackson SerializationFeature be overridden per field or class?
  • How to add date and time under each post in guestbook in google app engine
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • JSON with duplicate key names losing information when parsed
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo
  • Symfony2: How to get request parameter
  • Delete MySQLi record without showing the id in the URL
  • Return words with double consecutive letters
  • Unanticipated behavior
  • Comma separated Values
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • log4net write single file for each call to log.info
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • Getting error when using KSoap library to consume .NET web services
  • Trying to get generic when generic is not available
  • How to push additional view controllers onto NavigationController but keep the TabBar?