How the models should look like in Django 1.11 so that I can write this data in them? And how to write this data?
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}
]
[
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "Sincere#april.biz",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
]
You should create
A user model with first_name, last_name, username, email
An address model with those fields and a foreign key to user
And another model with a ForeignKey to user with title and body
here is an example from the documentation
from django.db import models
class Person(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
Django has a built-in user model if you prefer.
Related
I have a a REST API that when I call with GET for example from a browser I get a proper response like:
[
{"name": "jack",
"id" : 23
},
{"name": "joe",
"id" : 45
},
{"name": "james",
"id" : 56
}
]
So now in ADF I add a Web Activity and call the same API.
If at all possible: I want to have those items from the response in a array variable so I can loop through them.
How do I do this?
I have created a Set Variable activity and connected to output of my WebAPI call like picture below
and my pipeline variable is called apiCallOutput with type of Array.
Looking in Pipeline Run, the output of the Web APICall is like this:
{
"Response": "[
{"name": "jack",
"id" : 23
},
{"name": "joe",
"id" : 45
},
{"name": "james",
"id" : 56
}
]",
"typicalMetaData" : "stuff That Azure adds"
}
The following is a demonstration of how you can loop through items (and use its values) from the response which is returned using Web activity.
The following is the data that would be returned by my sample web activity (a sample provided, there are 100 items in total). I am just retrieving just userId and title for demonstration.
[
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
},
{
"userId": 1,
"id": 2,
"title": "qui est esse",
"body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla"
}
]
You can directly use the Response in For Each activity. For items field in the for each activity, you can use the following dynamic content.
#json(activity('Web1').output.Response)
Now you can access the item values inside the for each loop with 2 set variable activities. (provided dynamic content for your case)
#to get name value
#string(item().name)
#to get id value
#string(item().id)
Now when you debug the pipeline, you can see that the required values will be retrieved.
The output for value1 set variable activity.
The output for value2 set variable activity.
This way you can assign the item values into variables (String type) and use them inside for each directly.
NOTE:
You can directly use the values of an item as #item().name and #item().id without using set variable activity activity as well.
I am using axios to fetch some data from typicode api.
The result I am getting is some junk like this.
// apis.js
const axios = require('axios');
const getRequest = async () => {
const res = await axios.get('https://jsonplaceholder.typicode.com/posts/1');
console.log(res.data);
}
getRequest();
I am running this code using command node apis.
I am expecting result as below, as shown mentioned at https://jsonplaceholder.typicode.com/posts/1
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}
The code is completely fine and works on my machine. This must be a problem with your environment. Are you inside a VPN of a company or make this call from a server that sits in a special network or anything like that?
Someone could please point me what I need do to get the nuxt axios return which works inside vuetify v-for?
I'm using the following code:
async asyncData() {
let res = await axios.get('https://jsonplaceholder.typicode.com/posts')
console.log(res)
let objectPosts = {}
objectPosts = res.data
return (posts: objectPosts)
},
My componnent data is:
data() {
return {
posts: {}
}
},
My v-for is:
<article v-for="(post, index) in posts" :key="index">
And the error I'm getting is:
[Vue warn]: Error in render: "TypeError: Cannot read properties of undefined (reading 'length')"
If I fill my componnent data with the json as object manually works fine, example:
data() {
return {
posts: [
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
},
{
"userId": 1,
"id": 2,
"title": "qui est esse",
"body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla"
}
]
}
},
Console log show the array from axios too.
The application is using SSR, my initial guess was on be an issue with async, page get rendered first and object don't exists triggering this error.
Since its a list of objects shouldn't it be like this? :
data() {
return {
posts: {[]}
}
},
After read a lot of similar situations here and on social networks, have found this one:
Object assignment in Vue.js method
Then I have tried make the default values for component data like docs sayed to do:
https://v2.vuejs.org/v2/guide/reactivity.html?redirect=true#Declaring-Reactive-Properties
Other errors come out.
After some tries debugging (removing items from object one by one), have found in the original component there a lot of v-for and nuxt-link.
Inside v-for will drop errors on some situations.
Inside nuxt-link will not accept null (empty default object) or blank values.
Conclusion:
Seems I will need validate the entire object / array always and in the end force an Object.assign. Since I haven't made the API yet, solution will be hardcode an json file to read local.
You need to change the type of your posts to Array []
I have an array with 100 objects from an API, every object has an "user Id" key.
The array is something like:
[{ "userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
},
{
"userId": 1,
"id": 2,
"title": "qui est esse",
"body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla"
}, etc ]
How can I display all the objects in console? After this I have to search in array for a specific userId introduced by the user in the main page of application, I use express, body-parser, https from node.js.
app.post("/", function(req, res){
var userId = req.body.userId;
console.log(userId);
});
How can I show all the objects in console?
Assuming that you receive the array a variable name apiResults
console.log(apiResults) //or
console.log(JSON.stringify(apiResults))
I have to search in array for a specific userId..?
Use the Array.protype.some method to return a specific item from an array
var specificUser = apiResults.some(item => item.userId === preferedUser);
asset shipment identified by shipId{
o string shipId
o TemperatureThresholdEvent[] temperatureReading
}
event TemperatureThresholdEvent{
.....
}
I'm trying to have Array of TemperatureThresholdEvent in Shipment Asset. Is the model declaration valid?
You can create an Array of the event in model file. It will work as an only Array field.
Example:
namespace org.example.basic
asset SampleAsset identified by assetId {
o String assetId
--> SampleParticipant owner
o String value
o SampleEvent[] sampleEvent
}
Created Asset Contain:
{
"$class": "org.hyperledger.composer.system.AddAsset",
"resources": [
{
"$class": "org.example.basic.SampleAsset",
"assetId": "4467",
"owner": "resource:org.example.basic.SampleParticipant#7145",
"value": "Esse laboris quis consectetur.",
"sampleEvent": [
{
"$class": "org.example.basic.SampleEvent",
"asset": "resource:org.example.basic.SampleAsset#5945",
"oldValue": "Proident aliqua id ex.",
"newValue": "Esse ex aliqua exercitation sit.",
"eventId": "6719",
"timestamp": "2019-09-26T05:08:12.554Z"
}
]
}
],
"targetRegistry": "resource:org.hyperledger.composer.system.AssetRegistry#org.example.basic.SampleAsset",
"transactionId": "7ecd4664-c0d2-4b56-871e-6ff1ae9c4b56",
"timestamp": "2019-09-26T05:08:20.448Z"
}