How to iterate over each user in database django tempting language
Tag : django , By : user180941
Date : March 29 2020, 07:55 AM
this will help When you sign up for the site I am in the process of building, you pick whether you want to be a 'user' or a 'worker' and enter your location. For the workers, I want to display all the people trying to use the service('user') in the same location as the worker. I have the following model: , You should do that in your view and then send it to your html: def home(request):
if request.user.profile.role == 'WORKER':
workers_with_same_location = Profile.objects.filter(location=request.user.location, role='WORKER').exclude(id=request.user.id)
return render(request, 'core/home.html', {'user': request.user, 'other_workers': workers_with_same_location})
else:
render(request, 'core/home.html', {'user': request.user})
{% if user.profile.role == 'USER' %}
<h1>User Account</h1>
{% elif user.profile.role == 'WORKER' %}
<h1>Worker Account</h1>
{% for worker in other_workers %}
<h1>{{ worker.user.username }}</h1>
{% endfor %}
{% else %}
<h1>Error</h1>
{% endif %}
|
How to sequentially iterate through object values of a Map in Flutter and to return each value one by one as you iterate
Date : March 29 2020, 07:55 AM
With these it helps The below is a demo using the video player plugin. Instead of a Map, per Remi's recommendation in the comments to your question above, I created a basic video model with title and controller properties and added them to a List. It's much easier to use a List (with proper models) if you're looking to make a YouTube-like feed (most likely using a ListView or CustomScrollView). Ensure your pubspec.yaml is updated with your video assets (and change the below filenames), and the example should work for you. The listeners below will print when the video is initialized and the duration. import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Video Player Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Video Player Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<VideoModel> _controllers = [];
@override
void initState() {
super.initState();
_controllers = [
VideoModel(
title: 'Alpha',
controller: VideoPlayerController.asset('assets/videos/small.mp4')),
VideoModel(
title: 'Beta',
controller: VideoPlayerController.asset('assets/videos/small.mp4')),
VideoModel(
title: 'Gamma',
controller: VideoPlayerController.asset('assets/videos/small.mp4')),
];
_controllerLooper();
}
_controllerLooper() {
for (VideoModel video in _controllers) {
final listener = () {
if (video.controller.value.initialized) {
print('${video.title} - video initialized');
}
print('${video.title} duration: ${video.controller.value.position}');
};
video.controller
..addListener(listener)
..setVolume(1.0)
..setLooping(true)
..initialize();
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: ListView.builder(
itemCount: _controllers.length,
itemBuilder: (context, index) {
final controller = _controllers[index].controller;
return GestureDetector(
onTap: () {
if (controller.value.isPlaying) {
controller.pause();
} else if (!controller.value.isPlaying) {
controller.play();
}
},
child: AspectRatio(
aspectRatio: 16.0 / 9.0,
child: VideoPlayer(_controllers[index].controller),
),
);
}),
);
}
}
class VideoModel {
VideoModel({this.title, this.controller});
final String title;
final VideoPlayerController controller;
}
|
create a iterate object with a group of tree from a iterate object in python
Tag : python , By : Daniel Reslie
Date : March 29 2020, 07:55 AM
wish helps you You can expand on what you already did for groups of two, but with one more variable for the third item: def func(iterate):
i, j, k = tee(iterate, 3)
next(j, None)
next(k, None)
next(k, None)
return zip(i, j, k)
l = [1,2,3,4,5]
for a, b, c in func(l):
print(a, b, c)
1 2 3
2 3 4
3 4 5
|
BotComposer, how to iterate through the characters of a string using lg language?
Date : March 29 2020, 07:55 AM
|
How to iterate a list of objects using logic:iterate and display each object property values in jsp?
Tag : java , By : Michael Gunderson
Date : March 29 2020, 07:55 AM
|