<s> from __future__ import unicode_literals <EOL> from django . conf import settings <EOL> from django . core import checks <EOL> from django . core . exceptions import FieldDoesNotExist <EOL> from django . db import models <EOL> class CurrentSiteManager ( models . Manager ) : <EOL> "<STR_LIT>" <EOL> use_in_migrations = True <EOL> def __init__ ( self , field_name = None ) : <EOL> super ( CurrentSiteManager , self ) . __init__ ( ) <EOL> self . __field_name = field_name <EOL> def check ( self , ** kwargs ) : <EOL> errors = super ( CurrentSiteManager , self ) . check ( ** kwargs ) <EOL> errors . extend ( self . _check_field_name ( ) ) <EOL> return errors <EOL> def _check_field_name ( self ) : <EOL> field_name = self . _get_field_name ( ) <EOL> try : <EOL> field = self . model . _meta . get_field ( field_name ) <EOL> except FieldDoesNotExist : <EOL> return [ <EOL> checks . Error ( <EOL> "<STR_LIT>" % field_name , <EOL> obj = self , <EOL> id = '<STR_LIT>' , <EOL> ) <EOL> ] <EOL> if not field . many_to_many and not isinstance ( field , ( models . ForeignKey ) ) : <EOL> return [ <EOL> checks . Error ( <EOL> "<STR_LIT>" % ( <EOL> self . model . _meta . object_name , field_name <EOL> ) , <EOL> obj = self , <EOL> id = '<STR_LIT>' , <EOL> ) <EOL> ] <EOL> return [ ] <EOL> def _get_field_name ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . __field_name : <EOL> try : <EOL> self . model . _meta . get_field ( '<STR_LIT>' ) <EOL> except FieldDoesNotExist : <EOL> self . __field_name = '<STR_LIT>' <EOL> else : <EOL> self . __field_name = '<STR_LIT>' <EOL> return self . __field_name <EOL> def get_queryset ( self ) : <EOL> return super ( CurrentSiteManager , self ) . get_queryset ( ) . filter ( <EOL> ** { self . _get_field_name ( ) + '<STR_LIT>' : settings . SITE_ID } ) </s>
