I am inserting a new record in my model form where my model is child form containing a foriegn key. When I am submitting the form it give error it should be instance of the foriegn key.
Here is my model
class MMEditidState(models.Model):
state_id = models.IntegerField(primary_key = True)
state_dremelid = models.ForeignKey(MMDremelDump, db_column = 'state_dremelid')
assignee = models.CharField(max_length = 50)
state = models.CharField(max_length = 50)
role = models.CharField(max_length = 50)
date = models.DateTimeField()
class Meta:
db_table = u'mm_editid_state'
def __unicode__(self):
return u'%s %s' % (self.state_dremelid, self.assignee)
class MMEditidErrors(models.Model):
error_id = models.IntegerField(primary_key = True)
error_stateid = models.ForeignKey(MMEditidState, db_column = 'error_stateid')
feature_type = models.CharField(max_length = 20)
error_type = models.CharField(max_length = 20)
error_nature = models.CharField(max_length = 50, null = True)
error_details = models.CharField(max_length = 50)
error_subtype = models.CharField(max_length = 200)
date = models.DateTimeField()
class Meta:
db_table = u'mm_editid_errors'
def __str__(self):
return "%s" % (self.error_dremelid)
def __unicode__(self):
return u'%s' % (self.error_dremelid)
Here is my View
def qcthisedit(request, get_id):
if request.method == "POST":
form = forms.MMEditidErrorForm(get_id, request.POST)
if form.is_valid():
form.save()
return http.HttpResponseRedirect('/mmqc/dremel_list/')
else:
form = forms.MMEditidErrorForm(get_id)
return shortcuts.render_to_response('qcthisedit.html',locals(),
context_instance = context.RequestContext(request))
Here is my form
class MMEditidErrorForm(forms.ModelForm):
def __init__(self,get_id, *args, **kwargs):
super(MMEditidErrorForm, self).__init__(*args, **kwargs)
dremel = MMEditidState.objects.filter(pk=get_id).values('state_id')
dremelid = int(dremel[0]['state_id'])
self.fields['error_stateid'] = forms.IntegerField(initial = dremelid,
widget = forms.TextInput(
attrs{'readonly':'readonly'}))
feature_type = forms.TypedChoiceField(choices = formfields.FeatureType)
error_type = forms.TypedChoiceField(choices = formfields.ErrorType)
error_nature = forms.TypedChoiceField(choices = formfields.ErrorNature)
error_details = forms.TypedChoiceField(choices = formfields.ErrorDetails)
error_subtype = forms.TypedChoiceField(choices = formfields.ErrorSubType)
class Meta:
model = models.MMEditidErrors
exclude = ('error_id','date')
When I submit the form I am getting the error
Cannot assign "1": "MMEditidErrors.error_stateid" must be a "MMEditidState" instance.
So I have added line
get_id = MMEditidState.objects.get(pk = get_id)
Now I am getting the below mentioned error
int() argument must be a string or a number, not 'MMEditidState'
in form = forms.MMEditidErrorForm(get_id, request.POST)
Can someone help on this
Thanks
Vikram
I have solved this problem by simply using the custom forms instead of model forms. While storing the data in the database, I managed myself in the views.py
Related
class Quiz(models.Model):
name = models.CharField(max_length=200,default="",blank=False)
questions_count = models.IntegerField(default="")
description = models.TextField(max_length=10000,default="",blank=False)
created = models.DateTimeField(auto_now_add=True,null=True,blank=True)
slug = models.SlugField(max_length=200,unique=True,blank=False)
roll_out = models.BooleanField(default=False)
def __str__(self):
return self.name
class Question(models.Model):
quiz = models.ForeignKey(Quiz, on_delete=models.CASCADE,default="",related_name='quiz')
label = models.CharField(max_length=2000,default="")
order = models.IntegerField(default="")
def __str__(self):
return self.label
class Answer(models.Model):
question =models.ForeignKey(Question, on_delete=models.CASCADE,default="")
correct = models.BooleanField(default="")
text = models.CharField(max_length=1000,default="")
def __str__(self):
return self.text
class QuizTaker(models.Model):
quiz = models.ForeignKey(Quiz, on_delete=models.CASCADE,default="")
user = models.ForeignKey(User, on_delete=models.CASCADE,default="")
correct_answers = models.IntegerField(default=0)
completed = models.BooleanField(default=False)
timestamp = models.DateTimeField(auto_now_add=True)
score = models.FloatField()
def __str__(self):
return self.user.username
class Response(models.Model):
quiztaker = models.ForeignKey(QuizTaker, on_delete=models.CASCADE,default="")
question = models.ForeignKey(Question, on_delete=models.CASCADE,default="")
answer = models.ForeignKey(Answer,on_delete=models.CASCADE,null=True,)
def __str__(self):
return self.question.label
These are my models, I have been following a tutorial on yt by Jay Coding.
I want to limit the answer choice in response model related to question in admin panel/ model so that there is choice of answer related to particular question.
I am trying to build a rest-api for a movie-review website. The movie model contains a cast-field which is a list-field, when using ModelViewSets one can't POST ListFields through HTML, so I set blank = true for all list-fields thinking that I'll make a raw PATCH request to update the blank fields, but I am unable to do so.
models.py
class Movie(models.Model):
movie_name = models.CharField(max_length = 100, unique = True)
release_date = models.DateField(blank = True)
description = models.TextField(max_length = 500)
movie_poster = models.ImageField(blank = True)
directors = ListCharField(
base_field = models.CharField(max_length = 500),
max_length = 6 * 500,
blank = True
)
trailer_url = models.URLField()
cast = ListCharField(
base_field = models.CharField(max_length = 225),
max_length = 11 * 225,
blank = True
)
genre = ListCharField(
base_field = models.CharField(max_length = 225),
max_length = 11 * 255,
blank = True
)
avg_rating = models.FloatField(validators = [MinValueValidator(0), MaxValueValidator(5)])
country = models.CharField(max_length = 100)
language = models.CharField(max_length = 100)
budget = models.BigIntegerField(blank = True)
revenue = models.BigIntegerField(blank = True)
runtime = models.DurationField(blank = True)
Serializer
class MovieSerializer(ModelSerializer):
cast = ListField(
child = CharField(required = False), required = False,
min_length = 0
)
genre = ListField(
child = CharField(required = False), required = False,
min_length = 0
)
directors = ListField(
child = CharField(required = False), required = False,
min_length = 0
)
class Meta:
model = Movie
fields = '__all__'
I used djano-mysql for adding the ListCharField field-type.
https://i.stack.imgur.com/sC6Vw.png [The data without list field values]
https://i.stack.imgur.com/W3xea.png [request I tried to make]
https://i.stack.imgur.com/OPeJn.png [response that I received]
Original put request which resulted in an error response
https://i.stack.imgur.com/W3xea.png
The request had some trailing commas, due to which the API expected more values.
Here's the correct request-content -
{
"cast": [
"aamir",
"sakshi"
],
"genre": [
"biopic"
],
"directors": [
"nitesh tiwari"
]
}
I want to save the ID of a new Sale(); in $sale->voucher_series, how can I achieve this?
$sale = new Sale();
$sale->customerid = $request->customerid;
$sale->userid = \Auth::user()->id;
$sale->proof_type = $request->proof_type;
$sale->voucher_series = $request->saleId;
$sale->date_time = $mytime->toDateString();
$sale->total = $request->total;
$sale->status = 'Registered';
$sale->save();
If your voucher_series column is nullable field then it will work.
$sale = new Sale ();
$sale->customerid = $request->customerid;
$sale->userid = \Auth :: user()->id;
$sale->proof_type = $request->proof_type;
$sale->date_time = $mytime->toDateString ();
$sale->total = $request->total;
$sale->status = 'Registered';
$sale->save();
$sale->voucher_series = $sale->id;
I am trying to configure AD to IBM Appcenter Authentication but I receive an error mentioning The user registry operation could not be completed. The xx=xx entity is not in the scope of the defined realm. Specify an entity that is in the scope of the configured realm in the server.xml file.
My AD
Microsoft Active Directory
<ldapRegistry host="metchina.com.cn"
baseDN="xx=xx"
port="389"
id="LDAP1"
ldapType="Microsoft Active Directory"
bindDN="xx=xx"
bindPassword="xxxxxx">
</ldapRegistry>
I had tried to hit my AD from IBM appcenter authentication with different user id and I able to get the unable to find the xxx user id in AD error in the log. So I pretty sure my Appcenter able to hit AD. Not sure is AD configuration wrong or my server.xml configuration is wrong.
Below is the full error log
------Start of DE processing------ = [7/12/19 17:37:23:902 CST]
Exception = com.ibm.ws.security.registry.EntryNotFoundException
Source = com.ibm.ws.security.authentication.jaas.modules.UsernameAndPasswordLoginModule
probeid = 107
Stack Dump = com.ibm.ws.security.registry.EntryNotFoundException: CWIML0515E: The user registry operation could not be completed. The CN=xxxxxxx,ou=xxxxxxx,ou=xxxxxxx,ou=xxxxxxx,dc=xxxxxxx,dc=com,dc=cn entity is not in the scope of the defined realm. Specify an entity that is in the scope of the configured realm in the server.xml file.
at com.ibm.ws.security.wim.registry.util.SecurityNameBridge.getUserSecurityName(SecurityNameBridge.java:220)
at com.ibm.ws.security.wim.registry.WIMUserRegistry.getUserSecurityName(WIMUserRegistry.java:327)
at com.ibm.ws.security.authentication.internal.jaas.modules.ServerCommonLoginModule.getSecurityName(ServerCommonLoginModule.java:113)
at com.ibm.ws.security.authentication.jaas.modules.UsernameAndPasswordLoginModule.login(UsernameAndPasswordLoginModule.java:77)
at com.ibm.ws.kernel.boot.security.LoginModuleProxy.login(LoginModuleProxy.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:90)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:508)
at javax.security.auth.login.LoginContext.invoke(LoginContext.java:788)
at javax.security.auth.login.LoginContext.access$000(LoginContext.java:196)
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:698)
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:696)
at java.security.AccessController.doPrivileged(AccessController.java:703)
at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:696)
at javax.security.auth.login.LoginContext.login(LoginContext.java:597)
at com.ibm.ws.security.authentication.internal.jaas.JAASServiceImpl.doLoginContext(JAASServiceImpl.java:343)
at com.ibm.ws.security.authentication.internal.jaas.JAASServiceImpl.performLogin(JAASServiceImpl.java:329)
at com.ibm.ws.security.authentication.internal.jaas.JAASServiceImpl.performLogin(JAASServiceImpl.java:314)
at com.ibm.ws.security.authentication.internal.AuthenticationServiceImpl.performJAASLogin(AuthenticationServiceImpl.java:481)
at com.ibm.ws.security.authentication.internal.AuthenticationServiceImpl.authenticate(AuthenticationServiceImpl.java:207)
at com.ibm.ws.webcontainer.security.internal.BasicAuthAuthenticator.basicAuthenticate(BasicAuthAuthenticator.java:126)
at com.ibm.ws.webcontainer.security.internal.BasicAuthAuthenticator.handleBasicAuth(BasicAuthAuthenticator.java:117)
at com.ibm.ws.webcontainer.security.internal.BasicAuthAuthenticator.authenticate(BasicAuthAuthenticator.java:70)
at com.ibm.ws.webcontainer.security.WebAuthenticatorProxy.authenticate(WebAuthenticatorProxy.java:72)
at com.ibm.ws.webcontainer.security.WebAppSecurityCollaboratorImpl.authenticateRequest(WebAppSecurityCollaboratorImpl.java:1198)
at com.ibm.ws.webcontainer.security.WebAppSecurityCollaboratorImpl.determineWebReply(WebAppSecurityCollaboratorImpl.java:956)
at com.ibm.ws.webcontainer.security.WebAppSecurityCollaboratorImpl.performSecurityChecks(WebAppSecurityCollaboratorImpl.java:650)
at com.ibm.ws.webcontainer.security.WebAppSecurityCollaboratorImpl.preInvoke(WebAppSecurityCollaboratorImpl.java:567)
at com.ibm.wsspi.webcontainer.collaborator.CollaboratorHelper.preInvokeCollaborators(CollaboratorHelper.java:459)
at com.ibm.ws.webcontainer.osgi.collaborator.CollaboratorHelperImpl.preInvokeCollaborators(CollaboratorHelperImpl.java:270)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1109)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1005)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:75)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:927)
at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost$2.run(DynamicVirtualHost.java:279)
at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink$TaskWrapper.run(HttpDispatcherLink.java:1023)
at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink.wrapHandlerAndExecute(HttpDispatcherLink.java:417)
at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink.ready(HttpDispatcherLink.java:376)
at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:532)
at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.handleNewRequest(HttpInboundLink.java:466)
at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.processRequest(HttpInboundLink.java:331)
at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.ready(HttpInboundLink.java:302)
at com.ibm.ws.tcpchannel.internal.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:165)
at com.ibm.ws.tcpchannel.internal.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:74)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager.requestComplete(WorkQueueManager.java:501)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager.attemptIO(WorkQueueManager.java:571)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager.workerRun(WorkQueueManager.java:926)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager$Worker.run(WorkQueueManager.java:1015)
at com.ibm.ws.threading.internal.ExecutorServiceImpl$RunnableWrapper.run(ExecutorServiceImpl.java:232)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1160)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.lang.Thread.run(Thread.java:812)
Caused by: com.ibm.wsspi.security.wim.exception.InvalidUniqueNameException: CWIML0515E: The user registry operation could not be completed. The CN=xxxxxxx,ou=xxxxxxx,ou=xxxxxxx,ou=xxxxxxx,dc=xxxxxxx,dc=com,dc=cn entity is not in the scope of the defined realm. Specify an entity that is in the scope of the configured realm in the server.xml file.
at com.ibm.ws.security.wim.RepositoryManager.getRepositoryIdByUniqueName(RepositoryManager.java:163)
at com.ibm.ws.security.wim.RepositoryManager.getRepositoryId(RepositoryManager.java:128)
at com.ibm.ws.security.wim.ProfileManager.retrieveEntityFromRepository(ProfileManager.java:2170)
at com.ibm.ws.security.wim.ProfileManager.retrieveEntity(ProfileManager.java:1988)
at com.ibm.ws.security.wim.ProfileManager.getImpl(ProfileManager.java:403)
at com.ibm.ws.security.wim.ProfileManager.genericProfileManagerMethod(ProfileManager.java:247)
at com.ibm.ws.security.wim.ProfileManager.get(ProfileManager.java:194)
at com.ibm.ws.security.wim.VMMService.get(VMMService.java:208)
at com.ibm.ws.security.wim.registry.util.SecurityNameBridge.getUserSecurityName(SecurityNameBridge.java:185)
... 52 more
Dump of callerThis
Object type = com.ibm.ws.security.authentication.jaas.modules.UsernameAndPasswordLoginModule
tc = class com.ibm.websphere.ras.TraceComponent#d324336d
strings[0] = "TraceComponent[com.ibm.ws.security.authentication.jaas.modules.UsernameAndPasswordLoginModule,class com.ibm.ws.security.authentication.jaas.modules.UsernameAndPasswordLoginModule,[Authentication],com.ibm.ws.security.authentication.internal.resources.AuthenticationMessages,null]"
userRegistry = class com.ibm.ws.security.wim.registry.WIMUserRegistry#c6b9e0eb
tc = class com.ibm.websphere.ras.TraceComponent#bf37e35c
strings[0] = "TraceComponent[com.ibm.ws.security.wim.registry.WIMUserRegistry,class com.ibm.ws.security.wim.registry.WIMUserRegistry,[],null,null]"
CFG_KEY_REALM = "realm"
DEFAULT_REALM_NAME = "WIMRegistry"
realm = "WIMRegistry"
configManager = class com.ibm.ws.security.wim.ConfigManager#5c4bf4f9
tc = class com.ibm.websphere.ras.TraceComponent#dc67733c
SUPPORTED_ENTITY_TYPE = "supportedEntityType"
MAX_SEARCH_RESULTS = "maxSearchResults"
SEARCH_TIME_OUT = "searchTimeout"
RDN_PROPERTY = "rdnProperty"
ENTITY_TYPE_NAME = "name"
PRIMARY_REALM = "primaryRealm"
REALM = "realm"
REALM_NAME = "name"
KEY_CONFIG_ADMIN = "configurationAdmin"
ENTITY_NAME = "name"
DEFAULT_PARENT = "defaultParent"
EXTENDED_PROPERTY = "extendedProperty"
PROPERTY_NAME = "name"
DATA_TYPE = "dataType"
MULTI_VALUED = "multiValued"
ENTITY_TYPE_NAMES = "entityType"
DEFAULT_VALUE = "defaultValue"
DEFAULT_ATTRIBUTE = "defaultAttribute"
DEFAULT_MAX_SEARCH_RESULTS = 4500
DEFAULT_SEARCH_TIMEOUT = 600000
PAGE_CACHE_SIZE = "pageCacheSize"
DEFAULT_PAGE_CACHE_SIZE = 1000
PAGE_CACHE_TIMEOUT = "pageCacheTimeout"
DEFAULT_PAGE_CACHE_TIMEOUT = 30000
originalConfig = class org.apache.felix.scr.impl.helper.ReadOnlyDictionary#70644d07
config = class java.util.HashMap#656cf46a
realmNameToRealmConfigMap = class java.util.HashMap#f1015602
entityTypeMap = class java.util.HashMap#520edc16
listeners = class java.util.ArrayList#2f9a1ca8
defaultEntityMap = null
serialVersionUID = 9116500946872456363
vmmService = class com.ibm.ws.security.wim.VMMService#16f7634f
tc = class com.ibm.websphere.ras.TraceComponent#3981111f
KEY_FACTORY = "Factory"
KEY_CONFIGURATION = "Configuration"
KEY_TYPE = "com.ibm.ws.security.wim.repository.type"
KEY_ID = "config.id"
listeners = class java.util.ArrayList#35a93618
configMgr = class com.ibm.ws.security.wim.ConfigManager#5c4bf4f9
registryRealmNames = class java.util.HashSet#9c6e2c82
profileManager = class com.ibm.ws.security.wim.ProfileManager#79c3650a
repositoryManager = class com.ibm.ws.security.wim.RepositoryManager#6b165681
serialVersionUID = -5278720081853910862
TOKEN_DELIMETER = "::"
mappingUtils = class com.ibm.ws.security.wim.registry.util.BridgeUtils#5401eb02
tc = class com.ibm.websphere.ras.TraceComponent#7b21cf5e
groupLevel = 1
returnRealmInfoInUniqueUserId = false
groupLevelLock = "GROUP_LEVEL_LOCK"
allowDNAsPrincipalName = false
ALLOW_DN_PRINCIPAL_NAME_AS_LITERAL = "com.ibm.ws.wim.registry.allowDNPrincipalNameAsLiteral"
urRealmName = null
VMMServiceRef = class com.ibm.ws.security.wim.VMMService#16f7634f
configMgrRef = class com.ibm.ws.security.wim.ConfigManager#5c4bf4f9
hasFederatedRegistry = true
serialVersionUID = 7920840092070142204
loginBridge = class com.ibm.ws.security.wim.registry.util.LoginBridge#b539307b
tc = class com.ibm.websphere.ras.TraceComponent#d0b9a948
propertyMap = class com.ibm.ws.security.wim.registry.util.TypeMappings#61b9aead
mappingUtils = class com.ibm.ws.security.wim.registry.util.BridgeUtils#5401eb02
serialVersionUID = 6462275514085308184
displayBridge = class com.ibm.ws.security.wim.registry.util.DisplayNameBridge#82d5b852
tc = class com.ibm.websphere.ras.TraceComponent#6b15148b
propertyMap = class com.ibm.ws.security.wim.registry.util.TypeMappings#f036f17
mappingUtils = class com.ibm.ws.security.wim.registry.util.BridgeUtils#5401eb02
serialVersionUID = 869303381677205174
securityBridge = class com.ibm.ws.security.wim.registry.util.SecurityNameBridge#9f9cc0a6
tc = class com.ibm.websphere.ras.TraceComponent#dc4111fc
propertyMap = class com.ibm.ws.security.wim.registry.util.TypeMappings#27d89ea5
mappingUtils = class com.ibm.ws.security.wim.registry.util.BridgeUtils#5401eb02
serialVersionUID = 6696437810486401160
uniqueBridge = class com.ibm.ws.security.wim.registry.util.UniqueIdBridge#1b868bd0
tc = class com.ibm.websphere.ras.TraceComponent#ccf03ddd
propertyMap = class com.ibm.ws.security.wim.registry.util.TypeMappings#68ff5a9e
mappingUtils = class com.ibm.ws.security.wim.registry.util.BridgeUtils#5401eb02
serialVersionUID = 6072552178668405112
validBridge = class com.ibm.ws.security.wim.registry.util.ValidBridge#77fad8dd
tc = class com.ibm.websphere.ras.TraceComponent#af6e9abb
propertyMap = class com.ibm.ws.security.wim.registry.util.TypeMappings#4becbdfa
mappingUtils = class com.ibm.ws.security.wim.registry.util.BridgeUtils#5401eb02
serialVersionUID = 3219368833523822611
searchBridge = class com.ibm.ws.security.wim.registry.util.SearchBridge#2f3ce964
tc = class com.ibm.websphere.ras.TraceComponent#8a1b02e5
propertyMap = class com.ibm.ws.security.wim.registry.util.TypeMappings#ef0bb605
mappingUtils = class com.ibm.ws.security.wim.registry.util.BridgeUtils#5401eb02
groupRDN = "cn"
serialVersionUID = -8274377172336292275
membershipBridge = class com.ibm.ws.security.wim.registry.util.MembershipBridge#2e72a0ba
tc = class com.ibm.websphere.ras.TraceComponent#afb6a395
propertyMap = class com.ibm.ws.security.wim.registry.util.TypeMappings#667dc1e1
mappingUtils = class com.ibm.ws.security.wim.registry.util.BridgeUtils#5401eb02
serialVersionUID = -6409220961095031717
serialVersionUID = 8696398972883224688
username = null
urAuthenticatedId = "CN=xxxxxxx,ou=xxxxxxx,ou=xxxxxxx,ou=xxxxxxx,dc=xxxxxxx,dc=com,dc=cn"
serialVersionUID = -1034522143030294360
tc = class com.ibm.websphere.ras.TraceComponent#f591af3b
strings[0] = "TraceComponent[com.ibm.ws.security.authentication.internal.jaas.modules.ServerCommonLoginModule,class com.ibm.ws.security.authentication.internal.jaas.modules.ServerCommonLoginModule,[Authentication],com.ibm.ws.security.authentication.internal.resources.AuthenticationMessages,null]"
jsonWebTokenProperties = class java.lang.String[1]
String[0] = "com.ibm.ws.authentication.internal.json.web.token"
subjectHelper = class com.ibm.ws.security.authentication.utility.SubjectHelper#a1fe82be
tc = class com.ibm.websphere.ras.TraceComponent#9f96c8bf
strings[0] = "TraceComponent[com.ibm.ws.security.authentication.utility.SubjectHelper,class com.ibm.ws.security.authentication.utility.SubjectHelper,[],null,null]"
serialVersionUID = -1813770949958484743
serialVersionUID = -8018638276657617650
callbackHandler = class javax.security.auth.login.LoginContext$SecureCallbackHandler#be1f5c66
acc = class java.security.AccessControlContext#d118b575
STATE_NOT_AUTHORIZED = 0
STATE_AUTHORIZED = 1
STATE_UNKNOWN = 2
debugSetting = -1
debugPermClassArray = null
debugPermNameArray = null
debugPermActionsArray = null
debugCodeBaseArray = null
DEBUG_UNINITIALIZED_HASCODEBASE = 0
DEBUG_NO_CODEBASE = 1
DEBUG_HAS_CODEBASE = 2
DEBUG_DISABLED = 0
DEBUG_ACCESS_DENIED = 1
DEBUG_ENABLED = 2
domainCombiner = null
context = class java.security.ProtectionDomain[6]
authorizeState = 1
containPrivilegedContext = true
callerPD = null
doPrivilegedAcc = null
isLimitedContext = false
limitedPerms = null
nextStackAcc = null
debugHasCodebase = 0
createAccessControlContext = class java.security.SecurityPermission#144346a6
getDomainCombiner = class java.security.SecurityPermission#1e2b633
DEBUG_ACCESS = 1
DEBUG_ACCESS_STACK = 2
DEBUG_ACCESS_DOMAIN = 4
DEBUG_ACCESS_FAILURE = 8
DEBUG_ACCESS_THREAD = 16
DEBUG_ALL = 255
ch = class com.ibm.ws.security.jaas.common.callback.AuthenticationDataCallbackHandler#e6f88e48
authenticationData = class com.ibm.ws.security.authentication.WSAuthenticationData#940f74df
serialVersionUID = 2506413936667138927
$$$tc$$$ = class com.ibm.websphere.ras.TraceComponent#9d995d8d
subject = class javax.security.auth.Subject#4fd00d3b
serialVersionUID = -8308522755600156056
principals = class java.util.Collections$SynchronizedSet#918c4d68
serialVersionUID = 487447009682186044
serialVersionUID = 3053995032091335093
c = class javax.security.auth.Subject$SecureSet#98e77777
mutex = class java.util.Collections$SynchronizedSet#918c4d68
pubCredentials = class java.util.Collections$SynchronizedSet#b8dc5642
serialVersionUID = 487447009682186044
serialVersionUID = 3053995032091335093
c = class javax.security.auth.Subject$SecureSet#b81d152c
mutex = class java.util.Collections$SynchronizedSet#b8dc5642
privCredentials = class java.util.Collections$SynchronizedSet#8392c6ce
serialVersionUID = 487447009682186044
serialVersionUID = 3053995032091335093
c = class javax.security.auth.Subject$SecureSet#7d04c77c
mutex = class java.util.Collections$SynchronizedSet#8392c6ce
readOnly = false
combiner_constructor = class java.lang.reflect.Constructor#31c1f68b
clazz = class java.lang.Class#385cf9fe
slot = 0
parameterTypes = class java.lang.Class[1]
exceptionTypes = class java.lang.Class[0]
modifiers = 1
signature = null
genericInfo = null
annotations = null
parameterAnnotations = null
constructorAccessor = null
root = class java.lang.reflect.Constructor#b025ef5e
hasRealParameterData = false
parameters = null
declaredAnnotations = null
ACCESS_PERMISSION = class java.lang.reflect.ReflectPermission#e14510
override = false
reflectionFactory = class sun.reflect.ReflectionFactory#1f53b8fe
securityCheckCache = null
sysClassLoader = class sun.misc.Launcher$AppClassLoader#5c7b92a6
$assertionsDisabled = true
ucp = class sun.misc.URLClassPath#678cfb6
acc = class java.security.AccessControlContext#44339c2
sharedClassURLClasspathHelper = class com.ibm.oti.shared.SharedClassURLClasspathHelperImpl#ce023546
sharedClassMetaDataCache = class java.net.URLClassLoader$SharedClassMetaDataCache#31398506
closeables = class java.util.WeakHashMap#d9032981
showClassLoadingFor = class java.util.Vector#fddc4dab
showLoadingMessages = false
showClassLoadingProperty = "ibm.cl.verbose"
initialized = true
pdcache = class java.util.HashMap#f4e33023
debug = null
defaultCodeSource = class java.security.CodeSource#e46272ce
bootstrapClassLoader = class com.ibm.oti.vm.BootstrapClassLoader#f246447a
DELEGATING_CL = "sun.reflect.DelegatingClassLoader"
isDelegatingCL = false
applicationClassLoader = class sun.misc.Launcher$AppClassLoader#5c7b92a6
initSystemClassLoader = false
isAssertOptionFound = false
vmRef = 140708229739536
parent = class sun.misc.Launcher$ExtClassLoader#2c38d5bf
checkAssertionOptions = false
assertionLock = class java.lang.ClassLoader$AssertionLock#454f8a3d
defaultAssertionStatus = false
packageAssertionStatus = null
classAssertionStatus = null
packages = class java.util.Hashtable#a465656b
lazyInitLock = class java.lang.ClassLoader$LazyInitLock#79b1b5be
classSigners = null
packageSigners = class java.util.Hashtable#5f77b72c
emptyCertificates = class java.security.cert.Certificate[0]
defaultProtectionDomain = null
parallelCapableCollection = class java.util.Collections$SynchronizedMap#7018affb
classNameBasedLock = class java.util.Hashtable#6a5d7e4b
isParallelCapable = true
EMPTY_PACKAGE_ARRAY = class java.lang.Package[0]
methodTypeFromMethodDescriptorStringCache = null
allowArraySyntax = false
lazyClassLoaderInit = true
specialLoaderInited = true
internalAnonClassLoader = class java.lang.InternalAnonymousClassLoader#610cbd9f
getSub = null
doAsPA = null
doAsPEA = null
doAsPPA = null
doAsPPEA = null
overrideActive = false
PRINCIPAL_SET = 1
PUB_CREDENTIAL_SET = 2
PRIV_CREDENTIAL_SET = 3
NULL_PD_ARRAY = class java.security.ProtectionDomain[0]
sharedState = class java.util.HashMap#11e08545
serialVersionUID = 362498820763181265
DEFAULT_INITIAL_CAPACITY = 16
MAXIMUM_CAPACITY = 1073741824
DEFAULT_LOAD_FACTOR = 0.75
TREEIFY_THRESHOLD = 8
UNTREEIFY_THRESHOLD = 6
MIN_TREEIFY_CAPACITY = 64
table = class java.util.HashMap$Node[16]
Node[0] = null
Node[1] = null
Node[2] = null
Node[3] = null
Node[4] = null
Node[5] = class java.util.HashMap$Node#53a7d891
Node[6] = null
Node[7] = null
Node[8] = null
Node[9] = null
Node[10] = null
Node[11] = null
Node[12] = null
Node[13] = null
Node[14] = null
Node[15] = null
entrySet = null
size = 1
modCount = 1
threshold = 12
loadFactor = 0.75
keySet = null
values = null
options = class java.util.Collections$UnmodifiableMap#f37b6503
serialVersionUID = -1034234728574286014
m = class java.util.Collections$UnmodifiableMap#ca3a3403
serialVersionUID = -1034234728574286014
m = class java.util.HashMap#8bc20fb
keySet = null
entrySet = null
values = null
keySet = null
entrySet = null
values = null
temporarySubject = null
serialVersionUID = -8873301121271047884
$$$tc$$$ = class com.ibm.websphere.ras.TraceComponent#10c9a509
strings[0] = "TraceComponent[com.ibm.ws.security.jaas.common.modules.CommonLoginModule,class com.ibm.ws.security.jaas.common.modules.CommonLoginModule,[security],com.ibm.ws.security.jaas.common.internal.resources.JAASCommonMessages,null]"
I have model:
class Ingredient(models.Model):
KILOGRAM = 'kg'
LITER = 'ltr'
PIECES = 'pcs'
MUNITS_CHOICES = (
(KILOGRAM, 'Kilogram'),
(LITER, 'Liter'),
(PIECES, 'Pieces'),
)
name = models.CharField(max_length=200,unique=True,null=False)
slug = models.SlugField(unique=True)
munit = models.CharField(max_length=10,choices=MUNITS_CHOICES,default=KILOGRAM)
rate = models.DecimalField(max_digits=19, decimal_places=2,validators=[MinValueValidator(0)],default=0)
typeofingredient = models.ForeignKey(TypeOfIngredient, related_name='typeof_ingredient',null=True, blank=True,on_delete=models.PROTECT)
density_kg_per_lt = models.DecimalField(max_digits=19, decimal_places=2,verbose_name='Density (kg/lt)',null=True,blank=True,validators=[MinValueValidator(0)])
density_pcs_per_kg = models.DecimalField(max_digits=19, decimal_places=2,verbose_name='Density (pcs/kg)',null=True,blank=True,validators=[MinValueValidator(0)])
density_pcs_per_lt = models.DecimalField(max_digits=19, decimal_places=2,verbose_name='Density (pcs/lt)',null=True,blank=True,validators=[MinValueValidator(0)])
updated = models.DateTimeField(auto_now=True, auto_now_add=False)
timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)
When i get the api i also want to get field types like char, decimal, datetime etc
Something like the below api result, is it possible. Because i am using reactJs as frontend, i have tell the input what kind of field it can accept and also helps in sorting by text or number
{
"id": {value: 1,type: number},
"name": {value: "adark",type: charfield},
"rate": {value: "12.00",type: decimal},
"updated": {value: "2017-07-14T10:51:47.847171Z",type: datetime},
.......so on
}
The Corresponding Serializer would be as follows:
class IngredientSerializer(serializers.ModelSerializer):
name = serializers.SerializerMethodField()
rate = serializers.SerializerMethodField()
updated = serializers.SerializerMethodField()
class Meta:
model = Ingredient
fields = ('name', 'rate', 'updated')
def get_name(self, obj):
response = dict()
response['value'] = obj.name
response['type'] = obj.name.get_internal_type()
return Response(response)
def get_rate(self, obj):
response = dict()
response['value'] = obj.rate
response['type'] = obj.rate.get_internal_type()
return Response(response)
def get_updated(self, obj):
response = dict()
response['value'] = obj.updated
response['type'] = obj.updated.get_internal_type()
return Response(response)